使用soap-rpc-style的WSDL无法编译

时间:2011-07-05 19:42:18

标签: wsdl wsimport

我正在使用这个wsdl文件来描述我的webservice:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://www.myapproach.de/knowledgebase" name="Knowledgebase"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://www.myapproach.de/knowledgebase"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
    xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:rq="http://www.myapproach.de/knowledgebase">

    <wsdl:types>
    <xsd:schema>
      <xsd:import namespace="http://www.myapproach.de/knowledgebase" schemaLocation="GetValueRequest.xsd"/>
    </xsd:schema>
    </wsdl:types>

    <wsdl:message name="getValueForKey">
        <wsdl:part name="parameters" element="rq:getValueForKey" />
    </wsdl:message>
    <wsdl:message name="getValueForKeyResponse">
        <wsdl:part name="parameters" element="rq:getValueForKeyResponse" />
    </wsdl:message>

    <wsdl:portType name="KnowledgebasePortType">
        <wsdl:operation name="getValueForKey">
            <wsdl:input message="tns:getValueForKey" />
            <wsdl:output message="tns:getValueForKeyResponse" />
        </wsdl:operation>
    </wsdl:portType>

    <wsp:Policy wsu:Id="KnowledgebasePortBinding_WSAM_Addressing_Policy">
        <wsam:Addressing wsp:Optional="true">
            <wsp:Policy />
        </wsam:Addressing>
    </wsp:Policy>

    <wsdl:binding name="KnowledgebasePortBinding" type="tns:KnowledgebasePortType">
        <wsaw:UsingAddressing />
        <wsp:PolicyReference URI="#KnowledgebasePortBinding_WSAM_Addressing_Policy" />
        <!-- http://www.w3.org/2003/05/soap/bindings/HTTP/ -->
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
        <wsdl:operation name="getValueForKey">
            <soap:operation soapAction="http://www.myapproach.de/knowledgebase/getValueForKey" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="Knowledgebase">
        <wsdl:port name="KnowledgebasePortType" binding="tns:KnowledgebasePortBinding">
            <soap:address location="http://www.myapproach.de/knowledgebase" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

GetValueRequest.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.myapproach.de/knowledgebase"  xmlns:tns="http://www.myapproach.de/knowledgebase">

    <xsd:element name="getValueForKey" type="tns:getValueForKey" />
    <xsd:complexType name="getValueForKey">
        <xsd:sequence>
            <xsd:element name="arg0" type="xsd:string" minOccurs="0" />
            <xsd:element name="arg1" type="xsd:string" minOccurs="0" />
            <xsd:element name="arg2" type="xsd:double"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="getValueForKeyResponse" type="tns:getValueForKeyResponse" />
    <xsd:complexType name="getValueForKeyResponse">
        <xsd:sequence>
            <xsd:element name="return" type="xsd:string" minOccurs="0" />
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>

每次我运行wsimport时,都会收到此错误:

[wsimport] parsing WSDL...
[wsimport] [ERROR] Invalid wsdl:operation "getValueForKey": its a rpc-literal operation,  message part must refer to a schema type declaration
[wsimport]   line 27 of file:/path/MyFile.wsdl

我已将getValueForKey类型导出到xsd-schema文件中,所以我不明白这个错误...我正在尝试这一整天 grml

2 个答案:

答案 0 :(得分:1)

在发布问题后不久,我找到了答案: - )

而不是

<wsdl:message name="getValueForKey">
        <wsdl:part name="parameters" element="rq:getValueForKey" />
</wsdl:message>

使用此

<wsdl:message name="getValueForKey">
        <wsdl:part name="parameters" type="rq:getValueForKey" />
</wsdl:message>

必须使用属性“type”而不是“element”。

此外,soap:body元素必须具有命名空间

<wsdl:input>
        <soap:body use="literal" namespace="YourNormalNamespace" />
</wsdl:input>

答案 1 :(得分:0)

简而言之,wsdl部分必须具有类型,如果是RPC样式的webservices,则必须是文档样式。