Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After creating a wcf service how do I tell whether its restful or soap from the wsdl?

Tags:

rest

c#

soap

wcf

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>
like image 819
Exitos Avatar asked Jun 20 '11 16:06

Exitos


People also ask

How can I tell if service is SOAP or REST?

The very basic difference to find out a SOAP and Rest webservice is SOAP have a wsdl file whereas REST does not have. If you get wsdl it means that is a SOAP service.

Is WCF service REST or SOAP?

Normally, a WCF service will use SOAP, but if you build a REST service, clients will be accessing your service with a different architectural style (calls, serialization like JSON, etc.). Exposing a WCF service with both SOAP and REST endpoints, requires just a few updates to the codebase and configuration.

Is WCF service RESTful?

You can use WCF to build RESTful services in . NET. REST (Representational State Transfer) is an architecture paradigm that conforms to the REST architecture principles. The REST architecture is based on the concept of resources: It uses resources to represent the state and functionality of an application.

What is the difference between WCF REST service and Web API?

WCF does not provide any support for MVC features like controllers, routing, filter, auction results, etc. ASP.NET Web API supports MVC features like routing, controllers, results, filter, action, etc. It is not open source software. It is shipped with.Net framework.It is also available as an independent download.


2 Answers

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();
    }
}
like image 84
carlosfigueira Avatar answered Nov 11 '22 19:11

carlosfigueira


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.

like image 4
marc_s Avatar answered Nov 11 '22 19:11

marc_s