【问题标题】:build WSDL file for hello world soapServer为 hello world soapServer 构建 WSDL 文件
【发布时间】:2017-05-31 01:19:02
【问题描述】:

我在为我的老旧 PHP 肥皂服务器创建 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 服务器正常工作。我的目标是制作一个非常基本的“hello World”示例,并使用 WSDL 文件进行验证。

soapUI 给了我错误:

第 4 行:预期元素 'dataSet@urn:foo:bar' 而不是 'dataSet' 在元素 helloResponse@urn:foo:bar 第 7 行:预期元素 'dataSet@urn:foo:bar' 在元素内容结束之前 helloResponse@urn:foo:bar

如何更新 WSDL 文件以免出现此错误。

谢谢。

【问题讨论】:

    标签: php soap soapui soapserver


    【解决方案1】:

    如果有人偶然发现这个问题。请浏览这个 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 2023-03-03
      • 1970-01-01
      • 2011-12-28
      相关资源
      最近更新 更多