在WSDL文件中包含Schema Type

LCJ*_*LCJ 8 wcf xsd wsdl web-services contract-first

我手动创建了一个WSDL,它只有一个没有输入参数且没有输出参数的操作.

当我尝试从此WSDL创建客户端时,我收到以下错误:

无法导入wsdl:portType详细信息:运行WSDL导入扩展时抛出异常:System.ServiceModel.Description.DataContractSerializerMessageContractImporter错误:具有目标命名空间的架构" http://www.xmlns.mycompany.com/GAME/service/Associate/ 1.1 / '无法找到.XPath到错误源:// wsdl:definitions [@ targetNamespace =' http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/']/wsdl:portType [@ name ='GAMEAssociateIntf'] C :\工具箱\ BlueTest\BloodRedTest\BloodRedTest \服务

types (在客户机中使用)需要从本WSDL中的XML生成.我认为,在添加服务引用时,由于XML中的一些错误,该工具无法创建它.该XSD似乎是问题.

需要在WSDL中进行哪些更改才能创建代理?

注意:我试图包含WSDL本身定义的xml类型.[我不需要单独的文件进行架构保护]

WSDL

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GAMEAssociate" 
         targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
         xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
         xmlns="http://schemas.xmlsoap.org/wsdl/" 
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
         xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:wsp="http://www.w3.org/ns/ws-policy"
         >

<types>
<xsd:schema>
</xsd:schema>

<xsd:element name="myData">
  <xsd:complexType />
</xsd:element>

<xsd:element name="myDataResponse">
  <xsd:complexType />
</xsd:element>

</types>

<message name="getAllVicePresidentsRequest">
<part element="tns:myData" name="getAllVicePresidentsRequest"/>
</message>

<message name="getAllVicePresidentsResponse">
<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>
</message>

<portType name="GAMEAssociateIntf">
<operation name="getAllVicePresidents">
  <input message="tns:getAllVicePresidentsRequest"/>
  <output message="tns:getAllVicePresidentsResponse"/>
</operation>
</portType>

<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

<operation name="getAllVicePresidents">
  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
                  style="document"/>
  <input>
    <soap:body use="literal"/>
  </input>
  <output>
    <soap:body use="literal"/>
  </output>

</operation>

</binding>

<service name="GAMEAssociate">
<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">
  <soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>
</port>
</service>

</definitions>
Run Code Online (Sandbox Code Playgroud)

参考文献:

  1. WSDL - 没有输入 - 最佳实践
  2. 此WCF错误意味着什么:"自定义工具警告:无法导入wsdl:portType"
  3. 手工编写WSDL 1.1 Web服务契约
  4. 编写契约优先Web服务
  5. 从wsdl文件生成wcf服务器代码
  6. 如何获取wsdl输入和输出名称
  7. 内联架构
  8. 手卷SOAP请求

Ind*_*ght 6

我花了一些时间试图找出问题.你的wsdl的<types>部分是不正确的,它应该如下所示.有了这个,我现在可以用Java生成客户端文件.

<types>
<schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
          xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="myData">
     <complexType/> 
   </element>

   <element name="myDataResponse">
     <complexType/>
   </element>
</schema></types>
Run Code Online (Sandbox Code Playgroud)

UPDATE

基于下面的对话.添加了一个nillable属性.

<element name="myDataResponse" nillable="true">
<complexType/>
</element>
Run Code Online (Sandbox Code Playgroud)

请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
  <ns:myData/>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

响应

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)


LCJ*_*LCJ 1

我提到了内联架构。也感谢@Indoknight。工作合同 WSDL 如下。

\n\n

注意1:xsd 前缀和 targetNamespace 存在于 wsdl 内部使用的架构中type

\n\n

注2:nillable="true"适用于响应消息中使用的类型

\n\n

注意3:如果您遇到以下异常,请确保soapAction合同 WSDL 中的 WSDL 与从 WCF 服务生成的 wsdl 完全相同。一些用于生成服务代码的工具可能会根据自己的意愿修改 SOAP 操作\xe2\x80\x99。

\n\n
\n

故障代码:a:操作不支持

\n\n

故障字符串:由于 EndpointDispatcher 上的 ContractFilter 不匹配,无法在接收方处理带有 Action \' http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest \'的消息。这可能是因为合同不匹配(发送者和接收者之间的操作不匹配)或发送者和接收者之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

\n
\n\n

SOAP 操作 - 合同 WSDL

\n\n
  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"\n
Run Code Online (Sandbox Code Playgroud)\n\n

SOAP 操作 - 生成的 WSDL

\n\n
<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/IGAMEAssociateIntf/getAllVicePresidents"\n
Run Code Online (Sandbox Code Playgroud)\n\n

合同WSDL

\n\n
<?xml version="1.0" encoding="UTF-8"?>\n<definitions name="GAMEAssociate"\n     targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"\n     xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"\n     xmlns="http://schemas.xmlsoap.org/wsdl/"\n     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"\n     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"\n     xmlns:xsd="http://www.w3.org/2001/XMLSchema"\n     xmlns:wsp="http://www.w3.org/ns/ws-policy"\n     >\n\n<types>\n<xsd:schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"\n            xmlns:xsd="http://www.w3.org/2001/XMLSchema" >\n  <xsd:element name="myData">\n    <xsd:complexType />\n  </xsd:element>\n  <xsd:element name="myDataResponse" nillable="true">\n    <xsd:complexType />\n  </xsd:element>\n</xsd:schema>\n</types>\n\n<message name="getAllVicePresidentsRequest">\n<part element="tns:myData" name="getAllVicePresidentsRequest"/>\n</message>\n\n<message name="getAllVicePresidentsResponse">\n<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>\n</message>\n\n<portType name="GAMEAssociateIntf">\n<operation name="getAllVicePresidents">\n  <input message="tns:getAllVicePresidentsRequest"/>\n  <output message="tns:getAllVicePresidentsResponse"/>\n</operation>\n</portType>\n\n<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">\n<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>\n<operation name="getAllVicePresidents">\n  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"\n                  style="document"/>\n  <input>\n    <soap:body use="literal"/>\n  </input>\n  <output>\n    <soap:body use="literal"/>\n  </output>\n</operation>\n</binding>\n\n<service name="GAMEAssociate">\n<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">\n  <soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>\n</port>\n</service>\n\n</definitions>\n
Run Code Online (Sandbox Code Playgroud)\n\n

要求

\n\n
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">\n<soapenv:Header/>\n<soapenv:Body>\n  <ns:myData/>\n</soapenv:Body>\n</soapenv:Envelope>\n
Run Code Online (Sandbox Code Playgroud)\n\n

回复

\n\n
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\n<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\n  <myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>\n</s:Body>\n</s:Envelope>\n
Run Code Online (Sandbox Code Playgroud)\n