views:

5442

answers:

5

How to host wcf services,through TCP Ports,and how to listen to it?,and consume services through these TCP ports? i.e apart from net.tcp binding,is there someway to host and consume using TCP Ports.?

A: 

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.

Joachim Kerschbaumer
so basically,in windows xp hosting n consuming can be done in 3 ways1.self-hosting2.IIS3.as a Windows Serviceso opening a TCP port and consuming it,comes under self-hosting or is it another way of hosting n consuming wcf services or is there any other way?
More info on using netsh to open a port here: http://msdn.microsoft.com/en-us/library/ms733768.aspx
Darren Oster
A: 

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>
Ahmed Said
A: 

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.

AlexDrenea
so basically,in windows xp hosting n consuming can be done in 3 ways1.self-hosting2.IIS3.as a Windows Serviceso opening a TCP port and consuming it,comes under self-hosting or is it another way of hosting n consuming wcf services or is there any other way i.e under TCP?
I think you can host TCP with WAS in IIS 7.
Terry Donaghe
HTTP is an application protocol, not transport.
Wahnfrieden
+3  A: 

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.

Mark Seemann
so basically,in windows xp hosting n consuming can be done in 3 ways1.self-hosting2.IIS3.as a Windows Serviceso opening a TCP port and consuming it,comes under self-hosting or is it another way of hosting n consuming wcf services or is there any other way i.e under TCP?
Windows XP doesn't run IIS 7, so you can't host a TCP endpoint on IIS under XP. You can make a Windows Service host a WCF service, but that's just another example of Self Hosting.
Mark Seemann
A: 

I know its a bit late.. But, I suppose you could use the "WCF Service Host" app that comes with Visual Studio.

Prasanna K Rao