How do I host WCF services through TCP Ports, and how do I listen to it and consume services through these TCP ports?
That is, apart from the net.tcp binding, is there some way to host and consume using TCP ports?
How do I host WCF services through TCP Ports, and how do I listen to it and consume services through these TCP ports?
That is, apart from the net.tcp binding, is there some way to host and consume using TCP ports?
In WCF, you can host any service by yourself by creating an instance of the ServiceHost class, configure it with the correct endpoints and the service implementation you wish to expose, and call Open
on it. This is called self-hosting because you host the service (and its port listeners) from within your own application.
Alternatively, you can host your service in IIS, but you should be aware that while you can host WCF in IIS 6, it only allows you to host HTTP and HTTPS endpoints. If you want to host TCP endpoints in IIS (which is a good idea), you will need IIS 7.
Read more here.
you can use any port (provided you got the permission for it) to host your wcf services. when using IIS to host wcf services it is somewhat different, but in self-hosting environments, just add the port number to your base address and you're done. (when using Vista or Server 2008, you have to grant access to the port when not running with Administrator privileges (e.g. using netsh))
to use e.g. port 1337 for a http service (or net.tcp) just add ":1337/" to your base address and the rest is done for you.
May be this help
<services>
<service behaviorConfiguration="configname"
name="servicename">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="MyServiceBinding"
name="NetTcpBindingEndpoint" bindingName="MyServiceBinding"
contract="Interface">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="customBinding" bindingConfiguration="myMexTcpBinding"
name="MexTcpBindingEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:prot/TestService" />
</baseAddresses>
</host>
</service>
</services>
All HTTP bindings work with TCP for the transport layer. So, you could use HTTP bindings and IIS.6 to host an WCF service that runs on a specific TCP port.
Here's an walktrough on how to achieve this:
configure the service to run on your desired port from the configuration file (or code):
<service name="WCFService" behaviorConfiguration="DefaultBehaviour"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/WCFService" /> </baseAddresses> </host> <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="WCFService_mexEndpoint" contract="IMetadataExchange" /> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" name="WCFService_Endpoint" contract="WCFService.IService1" />
in IIS create a web site (or virtual directory) and configure it's binding to run on the port you chose in your baseAddress service configuration (8000 for the example above).
The result of the steps above is a WCF service that runs on TCP port 8000 for transport layer, using HTTP as the transport protocol.
Edit : I believe you are making a little confusion here. If what you are trying to achieve is a binary trasmitted package then the only solution at hand is the net.tcp binding, that is not compatible with IIS.6. If you just want to be able to select the TCP port of the connection, than any HTTP binding can do this as presented in my example above, and can be used in IIS.6.
I know its a bit late.. But, I suppose you could use the "WCF Service Host" app that comes with Visual Studio.
© 2022 - 2024 — McMap. All rights reserved.