web-services - 为什么使用 ?wsdl 后缀获取 URL 会产生没有操作信息的 wsdl?

标签 web-services wcf soap wsdl

我将 WCF WS 作为控制台应用程序运行,并且在使用 Web 浏览器获取 wsdl 时缺少操作信息 http://localhost:7903/MyService/?wsdl

这是为什么?下面提取的 wsdl 有用吗?

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/"xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:i0="http://www.mycompany.com/nis/MyService/wsdl/v1.0"xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing"xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="ptMyService" targetNamespace="http://tempuri.org/">
<wsdl:import namespace="http://www.mycompany.com/nis/MyService/wsdl/v1.0" location="http://0.0.0.0:7903/MyService/?wsdl=wsdl0"/>
<wsdl:types/>
<wsdl:binding name="BasicHttpBinding_IptMyService" type="i0:IptMyService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="ptMyService">
<wsdl:port name="BasicHttpBinding_IptMyService" binding="tns:BasicHttpBinding_IptMyService">
<soap:address location="http://0.0.0.0:7903/MyService/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

实际的 WSDL 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
  xmlns:cmp="http://www.mycompany.com/nis/MyService/v1.0"
  xmlns:msgs="http://www.mycompany.com/nis/MyServicemessages/v1.0"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://www.mycompany.com/nis/MyService/wsdl/v1.0"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
  targetNamespace="http://www.mycompany.com/nis/MyService/wsdl/v1.0"
  name="MyServiceService"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <types>
    <xsd:schema>
      <xsd:import schemaLocation="mycompany.nis.MyServicemessages.xsd" namespace="http://www.mycompany.com/nis/MyServicemessages/v1.0" />
      <xsd:import schemaLocation="mycompany.nis.MyService.xsd" namespace="http://www.mycompany.com/nis/MyService/v1.0" />
    </xsd:schema>
  </types>


  <message name="mMyService">
    <part name="parameters" element="msgs:components" />
  </message>
  <message name="mMyServiceResponse">
    <part name="parameters" element="msgs:syncresult" />
  </message>
  <message name="GetComponentRequest">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="msgs:GetComponent" />
  </message>
  <message name="GetComponentResponse">
    <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
    <part name="parameters" element="msgs:GetComponentResponse" />
  </message>
  <message name="RequestHeaderMessage">
    <part name="RequestHeaderPart" element="msgs:RequestHeader" />
  </message>
  <message name="ResponseHeaderMessage">
    <part name="ResponseHeaderPart" element="msgs:ResponseHeader" />
  </message>

  <portType name="ptMyService">
    <operation name="MyService">
      <input message="tns:mMyService" />
      <output message="tns:mMyServiceResponse" />
    </operation>
    <operation name="GetComponent">
      <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
      <input message="tns:GetComponentRequest" />
      <output message="tns:GetComponentResponse" />
    </operation>
  </portType>

  <binding name="bMyService" type="tns:ptMyService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
    <operation name="MyService">
      <soap:operation soapAction="MyServiceAction" />
      <input>
        <soap:body use="literal" />
        <soap:header message="tns:RequestHeaderMessage" part="RequestHeaderPart" use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
        <soap:header message="tns:ResponseHeaderMessage" part="ResponseHeaderPart" use="literal" />
      </output>
    </operation>
    <operation name="GetComponent">
      <soap:operation soapAction="GetComponent" />
      <input>
        <soap:body use="literal" />
        <soap:header message="tns:RequestHeaderMessage" part="RequestHeaderPart" use="literal" />
      </input>
      <output>
        <soap:body use="literal" />
        <soap:header message="tns:ResponseHeaderMessage" part="ResponseHeaderPart" use="literal" />
      </output>
    </operation>
  </binding>

  <service name="MyServiceService">
    <port name="MyServicePort" binding="tns:bMyService">
      <soap:address location="http://localhost:7903/MyService" />
    </port>
  </service>
</definitions>

最佳答案

确保您的操作方法没有ReplyAction设置为“*”,因为生成 WSDL 元数据的 WsdlExporter 会忽略此类方法。

[OperationContract(ReplyAction="*")]
string SampleMethod(string msg);

根据 MSDN :

Specifying an asterisk in the service instructs WCF not to add a reply action to the message, which is useful if you are programming against messages directly.

关于web-services - 为什么使用 ?wsdl 后缀获取 URL 会产生没有操作信息的 wsdl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35630511/

相关文章:

c# - 确定 WCF SOAP UserNamePasswordValidator 中客户端的 IP 地址

c# - Web 服务的一般异常

web-services - 卡塔隆工作室: How to create VerifyElementText Test Case for MTOM Enabled SOAP Web Services?

java - getPathParameters() 和 getQueryParameters() 之间的区别

wcf - 使用 PowerShell 的 New-WebServiceProxy 访问 net.tcp 端点

防火墙后面的 wsDualHttpBinding 和 netTcpBinding 的 WCF 问题

java - 基于非 HTTP 协议(protocol)的 SOAP

eclipse - 关于运行时位置的 Axis 错误

c# - WCF 4 Rest获取请求的IP?

.net - WCF Web 服务和 native ASP.NET 健康监控