带属性的 SOAP 请求
我似乎无法找出如何在不使用 XSD_ANYXML 编码的情况下为 SOAP 请求设置属性。
请求参数应如下所示
<request
xmlns:ns="/some/ns">
...
<ns:parameter attr="some attribute">
value
</ns:parameter>
...
</request>
当然,以下代码可以工作,但它相当丑陋(丑陋,因为它在应该使用 SOAP_Client API 的地方使用字符串连接,并且因为它不使用通用名称空间)
$param = new SoapVar(
'<ns_xxx:parameter xmlns:ns_xxx="/some/ns" attr="some attribute">
value
</ns_xxx:parameter>',
XSD_ANYXML
);
有没有更好的方法来创建带有命名空间和属性的 SOAP 请求参数?
我正在寻找某物。如下所示(这只是使用 SoapVar API 的一些伪代码):
$param = new SoapVar(
array(
'_' => 'value',
'attr' => 'some attribute'
),
SOME_ENCODING,
null,
null,
null,
'/some/ns'
);
I can not seem to find out how to set an attribute to a SOAP request without using the XSD_ANYXML encoding.
The request parameter should look as follows
<request
xmlns:ns="/some/ns">
...
<ns:parameter attr="some attribute">
value
</ns:parameter>
...
</request>
Of course the following code works, but it's rather ugly (ugly, because it uses string concatenation where it should use the SOAP_Client API and because it does not use the general namespace)
$param = new SoapVar(
'<ns_xxx:parameter xmlns:ns_xxx="/some/ns" attr="some attribute">
value
</ns_xxx:parameter>',
XSD_ANYXML
);
Is there a better way to create a SOAP request parameter with a namespace and an attribute?
I am looking for s.th. like the following (this is just some pseudo code using the SoapVar API):
$param = new SoapVar(
array(
'_' => 'value',
'attr' => 'some attribute'
),
SOME_ENCODING,
null,
null,
null,
'/some/ns'
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,您需要从 SoapClient 派生类并重写方法 __doRequest():
我希望这能解决您的问题。
For this, you need to derived the class from SoapClient and Override the method __doRequest():
I hope this will resolve your problem.
SOAP 不支持属性,也许您应该使用 REST!
编辑:
请检查正文样式 w3c:"4.3 SOAP Body" 并记住
您需要使用“soap-envelope”命名空间对消息进行编码并描述
您的 XML 类型这就是为什么您不能使用属性来描述您的消息数据。
但如果你问我,这是可能的!您可以使用自定义 SoapClient 解析器或类似的东西,并根据需要转换消息。
例如,RSS over SOAP http://www.ibm.com /developerworks/webservices/library/ws-soaprdf。
但是,问题是您会错过有关您的消息数据/类型的描述性信息,并且其他客户端无法轻松理解您的消息!
我对你的最佳实践是使用元素而不是属性,
我知道您需要修复您的 XML 模式,但这就是它的方式或切换到其他技术。
SOAP does not support attributes, may be you should use REST instead!
EDIT:
Please check the body style w3c:"4.3 SOAP Body" and remember that
you need to encode your message with "soap-envelope" namespace and describe
your XML types thats why, you can't use attributes to describe your message data.
But if you ask me, it can be made possible! You can use a custom SoapClient parser or something like that and convert your message as you like it.
A example of that may be RSS over SOAP http://www.ibm.com/developerworks/webservices/library/ws-soaprdf.
But, the problem would be that you would miss the descriptive information about your message data/types and other clients could not easy understand your messages!
My best practice for you would be to use elements instead of attributes,
i know you need to fix your XML schema but thats the way it goes or switch to a other technology.
SOAP 1 确实支持属性。以下是使用属性和值(来自客户端)的 Perl 代码示例:
SOAP 1 does support attributes. Here is an example of Perl code using both attributes and values (from a client):