gpt4 book ai didi

PHP SoapServer : How to disable 'Response' appending

转载 作者:行者123 更新时间:2023-12-04 06:24:03 25 4
gpt4 key购买 nike

我正在创建一个 SOAP 服务器(在 Symfony 中使用 ckWebservicePlugin),它需要符合以下请求和响应结构(我得到的是一个已经商定的规范)。

请求:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.net/schemas/USSD">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<USSDMessageRequest>
<id>43</id>
<msid>1234567890</msid>
<data>1*2</data>
</USSDMessageRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

回复:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<USSDMessageResponse>
<id>43</id>
<msid>1234567890</msid>
<data>
RESPONSE DATA
</data>
</USSDMessageResponse>
</SOAP-ENV:Body>

我遇到的问题是 SoapServer 总是将响应生成为所请求方法的名称 + 附加的“响应”。

因此发送的响应 XML 如下所示:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://bw.petr.appsdev/bw/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:USSDMessageRequestResponse>
<result>
<id>2</id>
<msid>1234565789</msid>
<data>RESPONSE DATA</data>
</result>
</ns1:USSDMessageRequestResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我希望输出是 <ns1:USSDMessageResponse> 而不是 <ns1:USSDMessageRequestResponse>

我正在使用的 WSDL 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservices" targetNamespace="http://bw.petr.appsdev/bw/" xmlns:tns="http://bw.petr.appsdev/bw/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<wsdl:types xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://bw.petr.appsdev/bw/">
<xsd:complexType name="userCredentials">
<xsd:sequence>
<xsd:element name="msisdn" type="xsd:string"/>
<xsd:element name="status" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="userCredentialsElement" type="tns:userCredentials"/>
<xsd:complexType name="USSDResponse">
<xsd:sequence>
<xsd:element name="id" type="xsd:string"/>
<xsd:element name="msid" type="xsd:string"/>
<xsd:element name="data" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="USSDResponseElement" type="tns:USSDResponse"/>
</xsd:schema>
</wsdl:types>
<wsdl:portType name="webservicesPortType">
<wsdl:operation name="USSDMessageRequest" parameterOrder="userCredentials id msid data">
<wsdl:input message="tns:USSDMessageRequestRequest"/>
<wsdl:output message="tns:USSDMessageResponse" name="USSDMessageResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservicesBinding" type="tns:webservicesPortType">
<soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="USSDMessageRequest">
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://bw.petr.appsdev/bw/USSDMessageRequest" style="rpc"/>
<wsdl:input xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="id msid data" use="literal" namespace="http://bw.petr.appsdev/bw/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<soap:header xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" message="tns:USSDMessageRequestRequest" part="userCredentials" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:input>
<wsdl:output xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" parts="result" use="literal" namespace="http://bw.petr.appsdev/bw/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<soap:header xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" message="tns:USSDMessageResponse" part="userCredentials" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:message name="USSDMessageRequestRequest">
<wsdl:part name="userCredentials" element="tns:userCredentialsElement"/>
<wsdl:part name="id" type="xsd:string"/>
<wsdl:part name="msid" type="xsd:string"/>
<wsdl:part name="data" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="USSDMessageResponse">
<wsdl:part name="userCredentials" element="tns:userCredentialsElement"/>
<wsdl:part name="result" type="tns:USSDResponse"/>
</wsdl:message>
<wsdl:service xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservicesService">
<wsdl:port xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="webservicesPort" binding="tns:webservicesBinding">
<soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://bw.petr.appsdev/bw/webservices.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

查看了 SoapServer 文档,浏览了 R. Richards 的 Pro Xml 和 Web Services,只是不知道如何告诉 SoapServer 响应名称应该是什么。

谢谢。

最佳答案

试试这个肮脏的 SoapVar hack:

public function USSDMessageRequest() {
$result = '<ns1:USSDMessageResponse> ... </ns1:USSDMessageResponse>'; // ns1 is dirty, depends on the SoapServer implementation
$result = new SoapVar($result, XSD_ANYXML);
return $result;
}

它在类似的问题上对我有用(不过我还没有用你们的网络服务测试它)。

关于PHP SoapServer : How to disable 'Response' appending,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6231191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com