6

The ONLY argument I can see for SOAP WCF over REST (json) wcf is the fact that once my service is created I can add a a reference in visual studio and I get a load of strongly typed classes ready for me and a client class that I can call all my webmethod through. It even sets up the web.config as far as I remember.

However when I expose a REST (json) service I still get a WSDL. So Im wondering is there still a way to build my references automatically?

Exitos
  • 29,230
  • 38
  • 123
  • 178
  • Have you tried adding a reference to the service the "old" way? [Code Table Example - Step 4](https://www.blackbaud.com/files/support/guides/infinitydevguide/Subsystems/inwebapi-developer-help/Content/InfinityWebAPI/coCodeTableExampleBizOps.htm). – Joshua Drake Apr 19 '12 at 16:37

4 Answers4

4

Not using WCF tools. Unlike with SOAP (which has an established protocol for describing services - WSDL), REST doesn't. WADL is one such protocol, but it isn't too widespread and WCF does not support it. You still get a WSDL, because WCF will describe everything it can from the service. However, the WSDL won't have a <wsdl:port> element, which would describe the REST endpoint, which is why you get the WSDL, but cannot generate a reference to it.

The post at http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx has a lot more info on this issue.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
0

Very old question, newer answer.

today using openapi (swagger) I can achieve this by using swagger inspector doing samples i can document my rest services as well as create a spec yml/json file allowing for validations and acceptance criteria as well as automated clients for java,python,c#,ruby,javascript and others I'm sure

Mickey Perlstein
  • 2,508
  • 2
  • 30
  • 37
-1

I would like top elaborate:

Although it is true you cannot get a WSDL add service reference with a JSON REST WCF service, what I do is create two met data hooks:

  1. is the operations returning JSON
  2. is a single XML op returning a class wrapper which includes all the service classes I allow, I call it Discover:

i.e.

public class Discover
{
  public Manager Manager {get;}
  public Employee Emp {get;}
  ....
}

[OperationContract]
public Discover DiscoverDTOs()
Mickey Perlstein
  • 2,508
  • 2
  • 30
  • 37
-1

You can, indirectly. While the client generated by Visual Studio won't work, that client implements an interface, also generated, that you can use like this:

WebChannelFactory<IService> factory = new WebChannelFactory<IService>(new Uri(endpointAddress));

IService proxy = factory.CreateChannel();

int result = proxy.Operation(1, 2, 3);

WebChannelFactory has another overload which accepts a WebHttpBinding, you can configure based on the service configuration, or you can make this configuration manually in your app.config file.

Tsahi Asher
  • 1,767
  • 15
  • 28