I know you can use multiple bindings, but if you implement a REST Service, must you use the webHttpBinding?
The webHttpBinding is what tells the WCF framework to communicate in a RESTful fashion - any other binding would define a different protocol. In your comment, you ask about wsHttpBinding - If you used that binding, you would not have a REST service, you'd have a SOAP web service.
You don't need to use directly WebHttpBinding. You can also use custom binding or your own binding but these bindings have to use HttpTransportBindingElement and WebMessageEncodingBindingElement. Both these binding elements are used by WebHttpBinding.
Related
I have been given access to a WCF/WSDL web service. I first do this:
svcutil.exe https://<thedomain>/foo/foo.svc?wsdl
to generate the C# class I need. I then plug this class into my C# application and it works fine. Note that I did not develop this server and cannot change it.
Question is this:
How can I communicate with this server without svcutil? I prefer to use just REST (GET and POST).
This way I would be able to connect to it from a Linux or Mac machine, not just Windows.
Update In my C# code, this is what happens:
WSHttpBinding binding = new WSHttpBinding();
EndpointAddress endpoint = new EndpointAddress("<address>");
fooClient client = new fooClient(binding, endpoint);
//(fooClient class came from svcutil)
//I now work with fooClient, call methods on it, etc.
That depends on the bindings in use by the service.
The "default" (read: most commonly used) bindings (basicHttp and wsHttp) implement SOAP 1.1 and SOAP 1.2 respectively, which means you're talking HTTP to the service, but using a specially crafted XML envelope in which your payload must be wrapped.
When the webHttpBinding is applied, you can talk "plain old XML" or JSON to the service, how to do so depends on the applied UriTemplate.
Note that there's no standardized metadata exchange for REST services (at least not as far as WCF is concerned), so even if the service is exposed using a REST binding, the information about how to construct the calls will not be exposed automatically but must instead be documented by the owners explicitly.
REST is an architectural approach. WCF service should be built for REST, not that you just can use it like this. In WCF service "by default" all requests are POSTs.
I wanted to ask is it possible to change format of message in netTcpBinding to not use Soap. I know it is possible with webHttpBindng but I want to know about netTcpBinding.
My belief is that NetTcpBinding itself is SOAP based; however, one can create custom binding using TCP transport of WCF to implement something own.
While creating a WCF data service, we do not have to define Endpoints in the config. What is the type of Binding that it uses, by default? Is there a way we can change the type of Binding being used?
WCF Data Services is an extension of the WCF REST services, and thus uses the webHttpBinding.
This binding cannot be changed for WCF Data Services - the whole architecture is so intimately tied to the HTTP and REST paradigm, it won't work over SOAP:
From what I remember, those created with ServiceHostFactory use basicHttp.
From playing with WebServiceHostFactory I could only seem to connect to it with WebHttpBinding leading me to believe that is the binding it uses underneath.
It states on: http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.webscriptservicehostfactory.aspx that WebScriptServiceHostFactory uses the WebHttpBinding
Hope that helped,
Anthony
EDIT: This page: http://msdn.microsoft.com/en-us/library/bb412204.aspx makes me believe that WCF Web Services default to using WebHttpBinding
I am really confused right now and I can't get any right answers anywhere.
My confusions are:
1) Isn't wsHttpBinging (which is beefed up basicHttpBinding) used in SOAP instead of REST and REST only uses webHttpBinding?
2) Also, DOES silverlight 4 with WCF (REST) support wsHttpBinding (VS2010)? I read that it does not everywhere on the net but I some how got silverlight 4 working with REST using wsHttpBinding.
NOTE: I am using Factory="System.ServiceModel.Activation.WebServiceHostFactory". Is this factory setting somehow bypassing my web.config setting for wsHttpBinding to make it work with webHttpBinding and i am thinking by my wsHttpBinding is working?
Thank you.
WCF uses SOAP by default - all binding except the webHttpBinding use SOAP.
If you want to do REST, you need to use the webHttpBinding.
1) Isn't wsHttpBinging (which is
beefed up basicHttpBinding) used in
SOAP instead of REST and REST only
uses webHttpBinding?
Yes - wsHttpBinding is a SOAP-based protocol - webHttpBinding is REST
2) Also, DOES silverlight 4 with WCF
(REST) support wsHttpBinding (VS2010)?
Silverlight 4 supports basicHttpBinding (SOAP), netTcpBinding (new in SL4 - SOAP) and webHttpBinding (REST).
NOTE: I am using
Factory="System.ServiceModel.Activation.WebServiceHostFactory".
Is this factory setting somehow
bypassing my web.config setting for
wsHttpBinding to make it work with
webHttpBinding and i am thinking by my
wsHttpBinding is working?
Yes, if you use the WebServiceHostFactory in your SVC file, then you're really getting the webHttpBinding (REST) implicitly. The WCF runtime will not look at your web.config for infos - it has all the information and settings it needs when you use WebServiceHostFactory - and you get webHttpBinding.
I have a WCF Service.
Is it possible to define a WCF service to have mulitple bindings
like
Method1 - WSHttpbinding
Method2 - BasicHttpbinding
Method3 - NETTcpBinding
Thanks.
No, you can't set a binding on method level.
What you can do: expose the entire service on multiple endpoints, where each endpoint is configured with a different binding (WsHttp, BasicHttp, Tcp, etc).