Java SOAP-WS客户端恐怖 [英] Java SOAP-WS client horror
问题描述
使用任何最常用的肥皂服务框架(至少是我尝试过的框架),并提出这种肥皂请求,看起来非常困难
It's looking amazingly difficult to use any of the most used soap services framework (at least those I've tried) and come up with this kind of soap request
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://bencws.foobar.com/doc/2008-01-01/"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/">
<soap:Header xmlns:foo="http://safe.foobar.com/doc/2007-01-01/" xmlns:oof="http://www.w3.org/2005/08/addressing">
<foo:AccessKeyId>0PKRFZMV7GRJ11N791R2</foo:AccessKeyId>
<foo:Timestamp>2008-03-07T23:55:22.693Z</foo:Timestamp>
<foo:Signature>someencodedstring</foo:Signature>
<oof:Action>SomeAction</oof:Action>
<oof:To>http://bencws.foobar.com</oof:To>
<oof:MessageID>120493412293</oof:MessageID>
<oof:ReplyTo>
<oof:Address> http://www.w3.org/2005/08/addressing/anonymous</oof:Address>
</oof:ReplyTo>
</soap:Header>
<soap:Body>
...
使用 cxf 我开始使用 cxf-codegen-plugin 从wsdl文件创建类存根。
但是,标准事情不允许更改soap:Header命名空间,甚至不允许在标签内添加内容(除非您向后弯曲两次)
With cxf I started using cxf-codegen-plugin to create classes stub from wsdl file. But then the "standard" thingie did not allow to change soap:Header namespace or even add stuff inside the tag (unless you bend over backwards twice)
通过 axis2 ,我使用了 WSDL2Java 并遇到同样的麻烦。
With axis2 I used WSDL2Java and endend up with the same kind of troubles.
我已经提出了看起来像是正确的肥皂请求,但是怪异的 foobar 服务将不会接受它们,除非我的 soap:Envelope 和 soap:Header 看起来并不完全一样。
I've come up with what would look like formally "correct" soap requests but freaking foobar service won't accept them anyways unless my soap:Envelope and soap:Header don't look exactly like that.
任何帮助将不胜感激。我应该再尝试其他吗?
现在我们正在考虑手动编写xml请求,这是我要避免的事情。
Any help will be much appreciated. Should I try something else? We're now at the point we're thinking to write the xml requests manually which is something I'd avoid.
推荐答案
使用CXF,将名称空间声明到soap:Envelope相对容易。您可以通过请求属性为客户端提供名称空间的Map->前缀:
With CXF, getting the namespaces declared onto the soap:Envelope is relatively easy. You can provide a Map of namespace -> prefix to the client via a request property:
((BindingProvider)proxy).getRequestContext().put("soap.env.ns.map", map);
因此,如果可以在那里声明foo和oof命名空间,则可以这样做。将它们添加到soap:Header绝对不是一件容易的事。 :-(
Thus, if you can have the foo and oof namespaces declared there, you could do that. Adding them onto the soap:Header is definitely not an easy thing to do. :-(
这篇关于Java SOAP-WS客户端恐怖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!