简体   繁体   English

在WSDL文件中包含Schema Type

[英]Include Schema Type in WSDL file

I created a WSDL by hand that has only one operation with no input parameter and no output parameter. 我手动创建了一个WSDL,它只有一个没有输入参数且没有输出参数的操作。

I am getting following error when I try to create a client from this WSDL: 当我尝试从此WSDL创建客户端时,我收到以下错误:

Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter Error: Schema with target namespace ' http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/ ' could not be found. 无法导入wsdl:portType详细信息:运行WSDL导入扩展时抛出异常:System.ServiceModel.Description.DataContractSerializerMessageContractImporter错误:具有目标命名空间的架构“ http://www.xmlns.mycompany.com/GAME/service/Associate/ 1.1 / '无法找到。 XPath to Error Source: //wsdl:definitions[@targetNamespace=' http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/ ']/wsdl:portType[@name='GAMEAssociateIntf'] C:\\toolbox\\BlueTest\\BloodRedTest\\BloodRedTest\\Service XPath到错误源:// wsdl:definitions [@ targetNamespace =' http ://www.xmlns.mycompany.com/GAME/service/Associate/1.1/'] / wsdl:portType [@ name ='GAMEAssociateIntf'] C :\\工具箱\\ BlueTest \\ BloodRedTest \\ BloodRedTest \\服务

The types (to be used in the client) need to be generated from the XML present in the WSDL. 需要从WSDL中存在的XML生成types (在客户端中使用)。 I think, while adding Service Reference, the tool is failing to create it due to some error in the XML. 我认为,在添加服务引用时,由于XML中的某些错误,该工具无法创建它。 The xsd seems to be the issue. xsd似乎是个问题。

What change need to be done in the WSDL to create the proxy ? 需要在WSDL中进行哪些更改才能创建代理?

Note: I am trying to include the xml types defined in WSDL itself. 注意:我试图包含WSDL本身定义的xml类型。 [I don't need a separate file for schema defenition] [我不需要单独的文件进行架构保护]

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

REFERENCES : 参考文献

  1. WSDL - no input - best practice WSDL - 没有输入 - 最佳实践
  2. What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType" 此WCF错误意味着什么:“自定义工具警告:无法导入wsdl:portType”
  3. Writing a WSDL 1.1 Web Service Contract by Hand 手工编写WSDL 1.1 Web服务契约
  4. Writing Contract-First Web Services 编写契约优先Web服务
  5. generate wcf server code from wsdl files 从wsdl文件生成wcf服务器代码
  6. How to get wsdl input and output names to appear 如何获取wsdl输入和输出名称
  7. Inline Schema 内联架构
  8. Hand rolled SOAP request 手卷SOAP请求

I spent some time trying to find out issues. 我花了一些时间试图找出问题。 Your <types> section of the wsdl is incorrect, it should be like below. 你的wsdl的<types>部分是不正确的,它应该如下所示。 With this, I can now generate client side artefacts in Java. 有了这个,我现在可以用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>

UPDATE UPDATE

Based on the conversation below. 基于下面的对话。 Added a nillable attribute. 添加了一个nillable属性。

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

Request 请求

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

Response 响应

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

wsi.org has a set of validation tools, which would certainly be worth trying. wsi.org有一套验证工具,肯定值得尝试。

The added benefit of using these tools is that you can then actually claim compliance with the WSDL specification(s). 使用这些工具的额外好处是,您可以实际声称符合WSDL规范。

I referred Inline Schema . 我推荐了Inline Schema Thanks to @Indoknight also. 还要感谢@Indoknight。 The working contract WSDL is given below. 工作合同WSDL如下。

Note1: The xsd prefix and targetNamespace is there in the schema that is used inside wsdl type 注意1:xsd前缀和targetNamespace存在于wsdl type使用的模式中

Note2: nillable="true" is applied for the type used in the response message 注2:nillable =“true”适用于响应消息中使用的类型

Note3: If you are getting following exception, make sure that the soapAction is exactly same in the contract WSDL and the wsdl generated from WCF service. 注意3:如果您遇到以下异常,请确保soapAction在合同WSDL和从WCF服务生成的wsdl中完全相同。 Some tools used for generating Service code may modify the SOAP action at it's own will. 用于生成服务代码的一些工具可以根据自己的意愿修改SOAP操作。

Faultcod: a:ActionNotSupported Faultcod:a:ActionNotSupported

Faultstring: The message with Action ' http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. Faultstring:由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action“ http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest ”的消息。 This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. 这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。 Check that sender and receiver have the same contract and the same binding (including security requirements, eg Message, Transport, None). 检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。

SOAP Action - Contract WSDL SOAP Action - 契约WSDL

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

SOAP Action - Generated WSDL SOAP Action - 生成的WSDL

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

Contract WSDL 合同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>

Request 请求

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

Response 响应

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM