开发者

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

开发者 https://www.devze.com 2023-03-14 08:25 出处:网络
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

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="VLSCo开发者_JAVA技巧ntentServiceBehaviour" 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>


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();
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消