Search code examples
wcfrestsoapwsdlsvcutil.exe

Can I communicate to a WCF (svcutil) web service using just GET or POST?


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.

Solution

  • 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.