How to host WCF through TCP ports?
Asked Answered
B

5

5

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?

Barrows answered 29/6, 2009 at 7:19 Comment(1)
so basically,in windows xp hosting n consuming can be done in 3 ways 1.self-hosting 2.IIS 3.as a Windows Service so 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?Barrows
F
8

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.

Freeholder answered 29/6, 2009 at 8:52 Comment(2)
so basically,in windows xp hosting n consuming can be done in 3 ways 1.self-hosting 2.IIS 3.as a Windows Service so 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?Barrows
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.Freeholder
P
0

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.

Puebla answered 29/6, 2009 at 7:23 Comment(2)
so basically,in windows xp hosting n consuming can be done in 3 ways 1.self-hosting 2.IIS 3.as a Windows Service so 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?Barrows
More info on using netsh to open a port here: msdn.microsoft.com/en-us/library/ms733768.aspxWoald
J
0

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>
Jarad answered 29/6, 2009 at 8:5 Comment(0)
P
0

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.

Poree answered 29/6, 2009 at 8:32 Comment(3)
so basically,in windows xp hosting n consuming can be done in 3 ways 1.self-hosting 2.IIS 3.as a Windows Service so 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?Barrows
I think you can host TCP with WAS in IIS 7.Orgiastic
HTTP is an application protocol, not transport.Woodring
S
0

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

Strobile answered 13/10, 2010 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.