PHP SoapServer:如何禁用“响应”追加
我正在创建一个 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:USSDMessageRequestResponse>
The 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 And Web Services,但不能弄清楚如何告诉 SoapServer 响应名称应该是什么。
谢谢。
I am creating a SOAP server (in Symfony using ckWebservicePlugin) which needs to comply with the following structure of request and response (I was given this as an already agreed specification).
Request:
<?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>
Reponse:
<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>
The trouble I'm having is with SoapServer always produces the response as name of the requested method + 'Response' appended.
So the response XML that is being sent out looks like this:
<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>
I would like the output to be <ns1:USSDMessageResponse>
rather than <ns1:USSDMessageRequestResponse>
The WSDL I'm using looks like this:
<?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>
Have checked SoapServer documentation, browsed through Pro Xml And Web Services by R. Richards and just can't figure out how to tell SoapServer what the response name should be.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个肮脏的 SoapVar hack:
它在类似的问题上对我有用(不过,我还没有用你的网络服务测试过它)。
Try this dirty SoapVar hack:
It has worked for me in a similar problem (I have not tested it with your web service, though).
您是否以 WSDL 模式创建 SoapServer?我的意思是你已经像这样构造了 SoapServer:
第一个参数不能为空。然后 SoapServer 应该根据 WSDL 创建响应。如果您仍然遇到问题,请尝试使用最新版本的 PHP。
Do you create SoapServer in WSDL mode? I mean you have construct SoapServer like this:
the first parameter must not be null. Then the SoapServer should create response according to the WSDL. If you have troubles anyway, try it with the newest release of PHP.