WSDL 文档文本,其中包含引用 XSD 类型的部件



我一直在阅读 WSDL 1.1 规范,有一件事对我来说似乎很奇怪 - 什么(除了 WS-I Basic Profile 之外)阻止我这样做:

<message name="helloRequest">
    <part name="arg1" type="xs:string" />
</message>
<message name="helloResponse">
    <part name="result" type="xs:string" />
</message>
<portType name="Port02">
    <operation name="hello">
        <input message="tns:helloRequest" name="helloRequest" />
        <output message="tns:helloResponse" name="helloResponse" />
    </operation>
</portType>
<binding name="Port02SoapBinding" type="tns:Port02">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="hello">
        <input name="helloRequest">
            <soap:body use="literal" />
        </input>
        <output name="helloResponse">
            <soap:body use="literal" />
        </output>
    </operation>
</binding>

它是文档/文字 Web 服务,但输入/输出消息包含引用 XSD(简单)类型的部分,而不是全局元素。

WSDL 片段并不那么可怕 - Axis1 和 CXF 都生成 soap 主体元素,这些元素的名称派生自部件名称,但 WSDL 1.1, 3.5: soap:body 说:

如果使用是文本,则每个部分都使用元素或类型属性引用具体的架构定义。在第一种情况下,[...]。在第二种中,部件引用的类型成为封闭元素的架构类型(文档样式的正文或 rpc 样式的部件访问器元素)。

这是否意味着生成的 SOAP 消息(根据 WSDL 规范)将如下所示(SOAP 正文中的文本内容)?

<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/1999/XMLSchema">
    <SOAP-ENV:Body xsi:type="xs:string">value</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是边缘情况 - 在实践中,所有Java(axis1,axis2,cxf,jaxrpc-ri)实现我检查了wrap String(或任何简单)类型,元素以部件名称命名,没有命名空间。

轴 1:

private static void _initOperationDesc1(){
    org.apache.axis.description.OperationDesc oper;
    org.apache.axis.description.ParameterDesc param;
    oper = new org.apache.axis.description.OperationDesc();
    oper.setName("hello");
    param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "arg1"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false);
    oper.addParameter(param);
    oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
    oper.setReturnClass(java.lang.String.class);
    oper.setReturnQName(new javax.xml.namespace.QName("", "result"));
    oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);
    oper.setUse(org.apache.axis.constants.Use.LITERAL);
    _operations[0] = oper;
}

JAXRPC-RI:

SOAPBlockInfo _bodyBlock = new SOAPBlockInfo(ns1_hello_arg1_QNAME);
_bodyBlock.setValue(arg1);
_bodyBlock.setSerializer(ns2_myns2_string__java_lang_String_String_Serializer);
_request.setBody(_bodyBlock);
...
private static final javax.xml.namespace.QName ns1_hello_arg1_QNAME = new QName("", "arg1");

所以你应该得到:

<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/1999/XMLSchema">
    <SOAP-ENV:Body>
       <arg1>value</arg1>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

编辑:同样在WSDL 2.0中没有消息,操作输入和输出必须引用元素(或 #any 或 #none 或 #other)。

最新更新