在创建wcf服务之后,我如何从wsdl中判断它是restful还是soap

本文关键字:判断 wsdl soap 还是 restful 服务 wcf 创建 之后 | 更新日期: 2023-09-27 17:59:32

我创建了一个服务,并收到一个页面,上面写着:

您已经创建了一个服务。

要测试此服务,您需要创建一个客户端并使用它来调用服务您可以使用命令行中的svcutil.exe工具使用以下语法:

但是,我该如何区分它是SOAP还是REST服务呢?我该如何从wsdl等中辨别?

服务配置:

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

更新:

你好,

我的配置是:

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

因此,基本上我浏览到.svc文件,并看到wsdl的链接。但是我怎么知道这是针对SOAP还是REST端点的呢。我是否正确配置了它?

感谢

更新:17:49(英国时间)

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

三月更新:18:22(英国时间)

Pete,试试这个-没有元数据发布,什么都没有-只有webHttpBinding-你应该不再看到任何WSDL。。。

<system.serviceModel>
   <services>
      <service name="VLSContentService">
          <endpoint name="rest" 
              address="" 
              binding="webHttpBinding" 
              contract="IVLSContentServiceREST" />
      </service>
   </services>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
</system.serviceModel>

在创建wcf服务之后,我如何从wsdl中判断它是restful还是soap

服务可以是REST和SOAP,WCF服务可以有多个端点,包括SOAP和REST的混合。在WSDL上,SOAP端点将显示在WSDL:definitions/WSDL:service/WSDL:port元素中;REST端点不会。因此,如果服务中只有一个端点,如果wsdl中有wsdl:port条目,那么它就是SOAP端点;否则就是REST.

您可以运行下面的代码并查看wsdl,发现它只显示了一个用于SOAP端点的wsdl:port元素。

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

如果WSDL,它就是SOAP服务。

REST没有WSDL。

REST有一个类似的概念,称为WADL-Web应用程序描述语言(WADL规范为PDF),但它远不如SOAP的WSDL那样完善和广泛使用。