Search

Loading...

Jun 20, 2010

WCF Service with webHttpBinding-basicHttpBinding-wsHttpBinding

WCF Services are designed to support distributed services where consumed client. Services are typically have WSDL interface which any of client can consumed regardless of platform on which WCF is hosted on.

WCF Services having three portions, Class having methods, host environment to host service, and one or more endpoints. Endpoints is place where WCF Client connects to WCF Service. In order to accommodate different communication scenario you just need to create more then one endpoints, for each endpoint you specify the address, a binding and a contract. Address is simple listener; contract specify the format of message which will arrive on specified address and binding is let you configure transport protocol, encoding and security. There are few built-in bindings represented by System.ServiceModel.Channels.Binding class to support HTTP, TCP and MSMQ protocols.

That was brief about WCF, now lets come to our business. We need to use wsHttpBinding + basicHttpBinding + webHttpBinding all together. That means we need to have multiple ends points to our service for different-different scenario. Here are the Service contract and operation contracts which we are going to use.

image

We will add one by one binding and check into WCF Test Client. First we will add basicHttpBinding which is designed for interoperability utmost important, its using SOAP 1.1.

image

You can see single endpoints having address and bindings, we have added binding configuration name basicBinding, which have property like security mode to None, readerQuotas having setting for client who is reading data from channel, also maxBufferSize which is parameter defined size which can be passed thru channel. We can see bindings in WCF Test Client it will show basic http bindings having one method. The value of maxBufferSize and maxReceivedMessgaeSize should be same for transfer mode is buffered. We have added behavior configuration for our service; serviceMetadata httpGetEnabled="true" allows simple HTTP Get request to succeed for metadata retrieval, by default WCF does not exposed metadata.

We can use WCF Test Client to check whether our setting are correct or not. So open WCF Test Client and add service url into service project.

image

It shows that we have exposed our service using basicHttpBinding. Now lets add wsHttpBinding binding, which is design for security, reliable messaging and transactions and its using SOAP 1.2 along with WS-Addressing 1.0 for message version which will carry additional protocol headers.

image

We have added binding configuration to set security and session reliability. The reliable session WCF provides ensures that messages sent between endpoints are transferred across SOAP or transport intermediaries and are delivered only once and, optionally, in the same order in which they were sent

Now let’s check on our WCF Test Client.

image

So, we can see two endpoints has been exposed, one is for basic binding and other is web script bindings. We already add basic and ws bindings lets add now web bindings.

image

One more endpoint, it’s now easy to expose more then one endpoint for single operation contract. If you need any security or additional settings then you can add binding configuration for this endpoint, but for now we don’t need any configurations. Let’s check our WCF Test Client.

image

We can see all these three binding for single operation contract! You can see wsdl file which will expose all these three bindings.

image

So we have exposed webHttpBinding + basicHttpBinding + wsHttpBinding endpoints in WCF service using same operation contract. We can use webHttpBinding for Silverlight application and also Json call.

8 comments:

Anonymous said...

I have been able to follow your earlier post about creating a WCF service and calling it from my iPhone. Thanks for the information.
I used basicHTTP binding for that sample and was curious if there is a way to use wsHTTP binding?

Anonymous said...

Is it possible to use wsHTTPBinding for a wcf service which is used from iPhone application?
thanks a lot..

Kamal said...

Can u plz do me a favour... my serivce is hosted on IIS and its having basicHttpBinding...Service is working properly..

But when i try to consume the wcf service by its URL. It gives me the error of 400 (Bad Request Error) or
You must provide a request body if you set ContentLength>0 or SendChunked==true. Do this by calling [Begin]GetRequestStream before [Begin]GetResponse.

DanyW said...

Interesting... I set mine up very similar to yours except I can't get my webHttpBinding endpoint to appear on my WCFTestClient tool. How did you manage that? I thought, being RESTful, the web endpoint wil not have metadata published?

Mehmet Karahan said...

I have same problem as DanyW, how did you manage to get webHttpBinding to be shown on wcftestclient?

Mehmet Karahan said...

I have same problem as DanyW, how did you manage to get webHttpBinding to be shown on wcftestclient?

Imran said...

Hello Mehmet Karahan & DanyW, send me an email to bhadelia.Imran@gmail.com, will send you working sample with 5 different bindings and all are coming in WCFTestClient.

shuvo said...

Hi Imran,

Can you please provide an working example of this ? I have already tried to contact in the provided email adddress.

Tanveer