为hello world soapServer构建WSDL文件

时间:2017-05-31 01:19:02

标签: php soap soapui 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.file

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

我成功地使SOAP服务器工作,直到您尝试根据WSDL文件验证它们。我的目标是打造一个非常基本的“你好世界”#34;使用验证的WSDL文件。

soapUI给了我错误:

  

第4行:预期元素&#39; dataSet @ urn:foo:bar&#39;而不是&#39; dataSet&#39;   这里是元素helloResponse @ urn:foo:bar第7行:预期元素   &#39;数据集@瓮:FOO:酒吧&#39;在元素内容结束之前   helloResponse @瓮:FOO:巴

如何更新WSDL文件以便我不会收到此错误。

感谢。

1 个答案:

答案 0 :(得分:0)

如果有人绊倒这个问题。请访问这个IBM站点,它有点技术性,但它具有开始使用SOAP和WSDL文件可能需要的所有基本信息。 Web Services Description Language (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>