Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF wsHttpBinding and BasicHttpBinding in same WCF Service Application

Tags:

wcf

I have been told that wsHttpBinding does not support older clients that still need to use older version of SOAP. I want to add a BasicHttpBinding endpoint in the same WCF Service Application so that clients can use either endpoint depending on their technology they are running. I am confused as to what the address to use for each of them. The default wsHttpBinding has no address set. What should the address be for BasicHttpBinding endpoint? Shouldn't the address for the wsHttpBinding be (for my example) http://localhost/WcfService1/Service1.svc ?

like image 647
user31673 Avatar asked Aug 24 '09 03:08

user31673


People also ask

What is the difference between BasicHttpBinding and WsHttpBinding?

Primarily BasicHttpBinding is designed to exchange SOAP over HTTP(s) only, just like old ASMX or . net web services and supports the WS-I BasicProfile. WsHttpBinding supports the advanced WS-* specification which includes WS-Addressing and WS-Security etc.

Which binding should I use if I want to safely allow my WCF service usable across machines?

netNamedPipeBinding. This binding is used to provide secure and reliable Named Pipe based communication between WCF services and WCF client on the same machine. It is the ideal choice for communication between processes on the same machine.

Which binding should be used if there is a requirement for the https mode of transportation?

WsHttpBinding. The WSHttpBinding class is designed for interoperation with services that implement WS-* specifications. The transport security for this binding is Secure Sockets Layer (SSL) over HTTP, or HTTPS.


1 Answers

There's two things you need to consider here:

  • if your hosting in IIS (or WAS as part of IIS7), you cannot set a base address - the base address for your service will be the virtual directory where the MyService.svc file lives. You can still set relative addresses, though

  • if you self-host, you typically will add base addresses in your config, so you can spare yourself having to spell out the entire address all the time (but you can - if you wish to do so).

So if you have your MyService.svc inside a virtual directory called MyApp on your localhost machine, and then use this config:

<service name="MyService" behaviorConfiguration="Default">
    <endpoint 
        address="wsHttp"  
        binding="wsHttpBinding" 
        contract="IMyService" />
  <endpoint 
        address="basic" 
        binding="basicHttpBinding" 
        contract="IMyService" />
</service>

then your "old-style" basicHttp service will be reachable at:

http://localhost/MyApp/MyService.svc/basic

and your new wsHttp driven service will be reachable at:

http://localhost/MyApp/MyService.svc/wsHttp

You can name those relative addresses (anything after .../MyApp/MyService.svc) anything you like - just make sure they're different from one another.

Hosting in IIS --> location (virtual directory) of your *.svc file becomes your base address.

If you self-host your service inside a console app or a Windows NT Service, you get to set your base addresses yourself:

<services>
  <service name="MyService" behaviorConfiguration="Default">
    <host>
      <baseAddresses>
         <add baseAddress="http://localhost:8185/Services/" />
      </baseAddresses>
    </host>
  </service>
</services>

Now in this case, your "old-style" basicHttp service will be reachable at:

http://localhost:8185/Services/basic

and your new wsHttp driven service will be reachable at:

http://localhost:8185/Services/wsHttp

You can define a base address for each of the transports, e.g. one for http://, one for net.tcp:// and so on.

And of course, if you really must, you can also define your complete addresses inside your <endpoint> element for each of the service endpoints - this gives you total flexibility (but only works in self-hosting scenarios).

Marc

like image 73
marc_s Avatar answered Oct 05 '22 10:10

marc_s