Before doing these steps; host your WCF service in IIS. I assumed that you already did that. And my target here is to host the service in WAS with net.tcp port 🙂 thank you.
Installing WAS (you can ignore these steps if WAS already installed)
1. Start inetmgr as administrator.
2. Default site >> Right click >> Edit Bindings.
3. If you have installed WAS correctly, it should list the default protocol bindings for the Web site, as shown in the following image:
4. Expand the Default Web Site item, and then click on your service (which is already hosted in IIS) application.
5. Advanced Settings.
6. In the Enabled Protocols add comma then net.tcp
7. Click OK.
Now, Lets Configure the Client Application to Connect by Using the TCP Protocol.
- Test the service on the browser (copy paste the url to your browser) and make sure if it works.
- Now, Regenerate the proxy using the svcutil.exe
- Open the new output.config
- Get the new TCP Binding & endpoint from the file and add it to your client app.
(The green bubbles below shows the net.tcp configuration).
5. Open the main() method in your client application and paste this line below:
|ProductsServiceClient proxy = new ProductsServiceClient();|
6. Run your app.
7. !!! What was that! Crash!
You have more than one endpoint available; you must specify which endpoint to use.
8. Just add your TCP endpoint’s name to your proxy constructor.
|ProductsServiceClient proxy = new ProductsServiceClient(“NetTcpBinding_IService”);|
TCP Endpoint name taken from:
11.Very important notes here:
- In most cases your machine will block the default TCP port; which is 808.
- For testing turn off your firewall.
- Add the port to the trusted ports:
- And to make sure that your Firewall will not block your port (if you do not turn it off); do the following:
ii. And finally; add the port to Inbound Rules and Outbound Rules.