簡體   English   中英

為Hello World SoapServer構建WSDL文件

[英]build WSDL file for hello world soapServer

我在為hellowold PHP soapserver創建WSDL文件時遇到問題。

服務器代碼:

<?php
function hello($soapData) {
    $finalresponse [] = new SoapVar ( $soapData->name, XSD_STRING, null, null, 'content' );
    $finalresponse [] = new SoapVar ( "1980-01-01", XSD_DATE, null, null, 'endDate' );
    $finalresponse [] = new SoapVar ( "1980-01-01", XSD_DATE, null, null, 'startDate' );
    return new SoapVar ( $finalresponse, SOAP_ENC_OBJECT, null, null, "" );
}

ini_set ( "soap.wsdl_cache_enabled", "0" );
$server = new SoapServer ( "http://example.com:8080/wsdl.wsdl", array ('soap_version' => SOAP_1_2 ) );
$server->addFunction ( "hello" );
$server->handle ();
?>

WSDL。文件

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://example.com:8083/wsdl.php" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:foo" xmlns:S2="urn:foo:bar" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="hello" targetNamespace="urn:foo">
    <types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="urn:foo:bar">
            <element name="dataSet">
                <complexType>
                    <sequence>
                        <element maxOccurs="unbounded" minOccurs="0" name="hello">
                            <complexType>
                                <sequence>
                                    <element name="hello" nillable="true" type="xsd:string"/>
                                    <element name="date" nillable="true" type="xsd:date"/>
                                </sequence>
                            </complexType>
                        </element>
                    </sequence>
                </complexType>
            </element>
            <element name="hello">
                <complexType>
                    <sequence>
                        <element name="name" nillable="true" type="xsd:string"/>
                    </sequence>
                </complexType>
            </element>
            <element name="helloResponse">
                <complexType>
                    <sequence>
                        <element ref="S2:dataSet"/>
                    </sequence>
                </complexType>
            </element>
        </schema>
    </types>
    <message name="hello_hello">
        <part name="parameters" element="S2:hello"/>
    </message>
    <message name="hello_helloResponse">
        <part name="parameters" element="S2:helloResponse"/>
    </message>
    <portType name="helloObj">
        <operation name="hello">
            <input message="tns:hello_hello"/>
            <output message="tns:hello_helloResponse"/>
        </operation>
    </portType>
    <binding name="helloObj" type="tns:helloObj">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="hello">
            <soap:operation soapAction="" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="helloService">
        <port name="helloObj" binding="tns:helloObj">
            <wsdl:documentation/>
            <soap:address location="http://example.com:8083/wsdl.php"/>
        </port>
    </service>
</definitions>

在您嘗試針對WSDL文件驗證它們之前,我已經成功使SOAP服務器正常工作。 我的目標是使用驗證的WSDL文件制作一個非常基本的“ hello World”示例。

soapUI給了我錯誤:

第4行:預期元素'dataSet @ urn:foo:bar'而不是元素helloResponse @ urn:foo:bar中的'dataSet'第7行:預期元素'dataSet @ urn:foo:bar'在內容末尾之前元素helloResponse @ urn:foo:bar

如何更新WSDL文件,這樣我就不會收到此錯誤。

謝謝。

如果有人偶然發現這個問題。 請瀏覽這個IBM站點,它有點技術性,但是它包含了開始使用SOAP和WSDL文件可能需要的所有基本信息。 Web服務描述語言(WSDL)

我確信以下WSDL可以做得更好,但是可以工作(在.net中驗證)

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:tns="http://ws.apache.org/axis2" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://ws.apache.org/axis2">
        <wsdl:types>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://org.apache.axis2/xsd" elementFormDefault="unqualified" attributeFormDefault="unqualified">
                <xs:element name="helloRequest">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name" nillable="true" type="xs:string"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="helloResponse">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element type="xs:string" name="content" />
                            <xs:element type="xs:date" name="endDate" />
                            <xs:element type="xs:date" name="startDate" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:schema>
        </wsdl:types>
        <wsdl:message name="helloRequestMessage">
            <wsdl:part name="part1" element="ns1:helloRequest"/>
        </wsdl:message>
        <wsdl:message name="helloResponseMessage">
            <wsdl:part name="part1" element="ns1:helloResponse"/>
        </wsdl:message>
        <wsdl:portType name="helloPortType">
            <wsdl:operation name="hello">
                <wsdl:input message="tns:helloRequestMessage"/>
                <wsdl:output message="tns:helloResponseMessage"/>
            </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="helloBinding" type="tns:helloPortType">
            <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
            <wsdl:operation name="hello">
                <soap:operation soapAction="hello" style="document" />
                <wsdl:input>
                    <soap:body use="literal"
                          namespace="http://example.com:8080/wsdl.php" />
                </wsdl:input>
                <wsdl:output>
                    <soap:body use="literal"
                          namespace="http://example.com:8080/wsdl.php" />
                </wsdl:output>
            </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="helloService">
            <wsdl:port name="helloPort" binding="tns:helloBinding">
                <soap:address location="http://example.com:8080/wsdl.php"/>
            </wsdl:port>
        </wsdl:service>
    </wsdl:definitions>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM