2

我是 WSDL 的新手,遇到了复杂类型的问题。基本上它好像输入消息没有使用 complexType 作为输入消息的类型。

我故意在输出消息上拼错了名称空间,以便可以返回传递给服务器的内容。返回的是客户端代码中发送的所有内容。我期望的是,如果让 soap 转换任何类型以匹配 WSDL 并去除任何额外内容,或者至少抛出一个错误。

我的代码是否有问题,或者我对输入应该发生什么的理解有问题?

提前致谢。

客户:

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient('http://example.com/Service_v1.wsdl', array("trace" => 1));

$request['UAT'] = 'fdgdfg';
$request['TemplateID'] = '236';
$request['To'] = 'email@address.com';
$request['From'] = 'mail@address.com';
$request['Org'] = 'PPRG';
$request['Order'] = 'order_number';
$request['Fake'] = 'fakefake';
$request['DeliverTimestamp'] = '2012-09-01 00:00:00';


var_dump($client->newEmail($request));

echo "<br><br><br>" .htmlentities($client->__getLastRequest() );

服务器:

ini_set("soap.wsdl_cache_enabled", "0");


class CreateEmail {

function newEmail($request) {
    return array('Status' => $request, 'ReferenceID' => 123);
    }
}


$server = new SoapServer("Service_v1.wsdl");

$server->setClass("CreateEmail");

$server->handle();

WSDL:

<definitions name="Service_v1"  targetNamespace="http://example.com/Service_v1" xmlns="http://schemas.xmlsoap.org/wsdl/"    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   xmlns:xsd="http://www.w3.org/2001/XMLSchema">


<wsdl:types>
    <xsd:element name="TransactionDetail">
        <xsd:complexType>
            <xsd:complexContent mixed="true">
                <xsd:restriction base="xsd:anyType">                    
                    <xsd:element name="UAT" type="xsd:boolean" minOccurs="0" maxOccurs="1"/>
                    <xsd:element name="TemplateID" type="xsd:integer" minOccurs="1" maxOccurs="1"/>
                    <xsd:element name="To" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                    <xsd:element name="From" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                    <xsd:element name="Org" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                    <xsd:element name="Order" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                    <xsd:element name="DeliverTimestamp" type="xsd:dateTime" minOccurs="0" maxOccurs="1"/>
                </xsd:restriction>
            </xsd:complexContent>
        </xsd:complexType>
    </xsd:element>

</wsdl:types>

<message name="CreateEmailRequest">
    <part name="emailInfo" element="tns:TransactionDetail"/>
</message>

<message name="CreateEmailReply">
    <part name="Status" type="xs:boolean"/>
    <part name="ReferenceID" type="xsd:integer"/>
</message>

<portType name='CreateEmailPortType'>
    <operation name='newEmail'>
        <input message='tns:CreateEmailRequest'/>
        <output message='tns:CreateEmailReply'/>
    </operation>
</portType>

<binding name='CreateEmailBinding' type='tns:CreateEmailPortType'>
    <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>

    <operation name='newEmail'>
        <soap:operation soapAction='urn:xmethods-delayed-quotes#newEmail'/>
        <input>
            <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
        </input>

        <output>
            <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
        </output>
    </operation>
</binding>

<service name='CreateEmailService'>
  <port name='CreateEmailPort' binding='CreateEmailBinding'>
    <soap:address location='http://example.com/CreateEmail.php'/>
  </port>
</service>

</definitions>
4

0 回答 0