8

我手动创建了一个 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 :\toolbox\BlueTest\BloodRedTest\BloodRedTest\Service

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

参考文献

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

3 回答 3

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>

更新

根据下面的对话。添加了一个nillable属性。

<element name="myDataResponse" nillable="true">
<complexType/>
</element>

要求

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

回复

<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>
于 2013-04-19T17:15:28.947 回答
1

wsi.org 有一套验证工具,当然值得一试。

使用这些工具的额外好处是,您实际上可以声称符合 WSDL 规范。

于 2013-04-26T13:14:50.910 回答
1

我提到了 Inline Schema。还要感谢@Indoknight。工作合同 WSDL 如下所示。

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

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

注意 3:如果您遇到以下异常,请确保soapAction合同 WSDL 和 WCF 服务生成的 wsdl 完全相同。一些用于生成服务代码的工具可能会随意修改 SOAP 操作。

Faultcod: a:ActionNotSupported

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

SOAP 操作 - 合同 WSDL

  <soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"

SOAP 动作 - 生成的 WSDL

<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/IGAMEAssociateIntf/getAllVicePresidents"

合同 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 targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
  <xsd:element name="myData">
    <xsd:complexType />
  </xsd:element>
  <xsd:element name="myDataResponse" nillable="true">
    <xsd:complexType />
  </xsd:element>
</xsd:schema>
</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>

要求

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

回复

<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>
于 2013-04-26T17:21:21.820 回答