5

I created a service and I'm presented with a page saying:

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

But how do I tell if its a SOAP or a REST service from that? How would I tell from the wsdl etc?

Service config:

<services> 
    <service name="VLSContentService"
             behaviorConfiguration="VLSContentServiceBehaviour" > 
        <endpoint name="rest" 
            address="" 
            behaviorConfiguration="VLSContentServiceEndpointBehaviour" 
            binding="webHttpBinding" 
            contract="IVLSContentServiceREST" /> 
        <endpoint name="soap" 
            address="soap" 
            binding="basicHttpBinding" 
            contract="IVLSContentServiceREST"/> 
    </service> 
</services>

UPDATE:

Hi Mark,

My config is:

 <services>
      <service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
        <endpoint name="rest" address="" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentServiceREST" />
        <endpoint name="soap" address="soap" binding="basicHttpBinding" contract="IVLSContentServiceREST"/>
      </service>
    </services>

So basically I browse to the .svc file and I see a link for a wsdl. But how do I know if thats for the SOAP or REST endpoint. Have I even configured it correctly?

Thanks

UPDATE: 17:49 (UK TIME)

<system.serviceModel>

  <!---Add the service-->
  <services>
    <service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
       <endpoint name="rest" 
           address="" 
           behaviorConfiguration="VLSContentServiceEndpointBehaviour" 
           binding="webHttpBinding" 
           contract="IVLSContentServiceREST" />
    </service>
 </services>
 <!---Add the behaviours-->
 <behaviors>
    <serviceBehaviors>
       <behavior name="VLSContentServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
       </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
       <behavior name="VLSContentServiceEndpointBehaviour">
         <webHttp />
       </behavior>
    </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
</system.serviceModel>

marc_s UPDATE: 18:22 (UK TIME)

Pete, try this - no metadata publishing, nothing - just webHttpBinding - you should not see any WSDL anymore...

<system.serviceModel>
   <services>
      <service name="VLSContentService">
          <endpoint name="rest" 
              address="" 
              binding="webHttpBinding" 
              contract="IVLSContentServiceREST" />
      </service>
   </services>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
</system.serviceModel>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Exitos
  • 29,230
  • 38
  • 123
  • 178
  • 2
    By RESTful one not having a WSDL at all! – Aliostad Jun 20 '11 at 16:08
  • Yes, obviously you get a WSDL - **because you have a SOAP endpoint (`name=soap`) defined in your service config!** Try it without the `basicHttpBinding` endpoint - you will **not** get a WSDL for just a REST endpoint. – marc_s Jun 20 '11 at 16:42
  • Hi Marc_s, I think we are getting our wires crossed now. I have actually taken the SOAP config out and still getting a wsdl. Carlos in the post below says this is because I have . – Exitos Jun 20 '11 at 17:06
  • You still have the metadata endpoint! You have "metadata exchange" enabled - this will publish a SOAP endpoint.... – marc_s Jun 20 '11 at 17:22

2 Answers2

5

The service can be both REST and SOAP, in a way that a WCF service can have multiple endpoints, including a mix of both SOAP and REST. On the WSDL, the SOAP endpoints will show up in the wsdl:definitions/wsdl:service/wsdl:port element; the REST endpoints will not. So if you only have one endpoint in the service, if there is a wsdl:port entry in the WSDL, then it's a SOAP endpoint; otherwise it's REST.

You can run the code below and look at the wsdl to see that it only shows up one wsdl:port element, for the SOAP endpoint.

public class StackOverflow_6414181
{
    [ServiceContract]
    public interface ITest
    {
        [OperationContract]
        [WebGet]
        string Echo(string text);
    }
    public class Service : ITest
    {
        public string Echo(string text)
        {
            return text;
        }
    }
    public static void Test()
    {
        string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
        ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
        host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
        host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), "soap");
        host.AddServiceEndpoint(typeof(ITest), new WebHttpBinding(), "rest").Behaviors.Add(new WebHttpBehavior());
        host.Open();
        Console.WriteLine("Host opened");

        Console.Write("Press ENTER to close the host");
        Console.ReadLine();
        host.Close();
    }
}
carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • cheers carlos, I am having another chat about why the wsdl is still showing up when I remove the SOAP binding. Should it? – Exitos Jun 20 '11 at 16:51
  • [I'm assuming that you meant that you removed the SOAP *endpoint*, not only the binding] Well, you enabled it (), so it will create a WSDL document for your service. It's not too common, but one reason why one would want to have a WSDL for a REST-only service is that the WSDL contains the data contract definitions (which will be generated if you use svcutil). The service contract, however, will likely not be correct (since things such as UriTemplate / WebGet / BodyStyle / etc don't show up in the WSDL). – carlosfigueira Jun 20 '11 at 16:56
4

If you have a WSDL - it's a SOAP service.

REST doesn't have WSDL.

REST has a similar concept called WADL - Web Application Description Language (WADL specification as PDF) - but that's not nearly as well established and widely used as WSDL for SOAP.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Hi, Sorry when I create a REST WCF service with c# it dos actually create a wsdl. Its there on the screen. – Exitos Jun 20 '11 at 16:13
  • Hi, okay here it is: – Exitos Jun 20 '11 at 16:35
  • @pete2k: well, yeah - you have **a SOAP endpoint** in your service - so obviously you'll get a WSDL - for **THAT SOAP ENDPOINT!** - but there's NOTHING for the REST endpoint - if you had only the REST endpoint, **there would be no WSDL**. My point is: if you have only a REST endpoint, there is no WSDL, since REST doesn't deal with WSDL. – marc_s Jun 20 '11 at 16:39
  • 1
    @Pete2k - `` defines a SOAP endpoint, and so you have a WSDL. Mark is correct that if you have a WSDL, then WCF either thinks it is a SOAP service, or it has been told to publish the SOAP WSDL (by having a MEX endpoint). – CodingWithSpike Jun 20 '11 at 16:39
  • 1
    @Pete2k - if you have "taken the binding for the REST endpoint out" as you stated, then that means you are left with the SOAP endpoint, so you would still have a WSDL. Did you mean the opposite; that you removed the SOAP endpoint, leaving only the REST one in the config? – CodingWithSpike Jun 20 '11 at 16:53