使用Axis 1.4设置自定义SOAP消息头 [英] Set custom SOAP header using Axis 1.4
问题描述
我试图消耗使用Axis一个.NET 2.0的Web服务。 我生成使用Eclipse插件WST Web服务客户端,它似乎确定为止。
I'm trying to consume a .NET 2.0 web service using Axis. I generated the web services client using Eclipse WST Plugin and it seems ok so far.
下面预期的SOAP头:
Here the expected SOAP header:
<soap:Header>
<Authentication xmlns="http://mc1.com.br/">
<User>string</User>
<Password>string</Password>
</Authentication>
</soap:Header>
我没有找到如何从Axis客户机配置此头的任何文件。
当我生成使用Visual Studio C#防爆preSS 2008客户端,它会生成一个名为认证类
有两个字符串属性(用户
和密码
)和所有客户端方法获得这个类作为第一个参数的对象,但没有发生一起轴WS客户端。
I didn't find any documentation on how to configure this header from an Axis client.
When I generated the client using Visual Studio C# Express 2008, it generates a class named Authentication
with two String attributes (User
and Password
) and all the client methods receive an object of this class as first parameter, but it did not happen with Axis WS client.
我怎么能在我的客户端调用设置此头?
How can I set this header in my client calls?
推荐答案
也许你可以用 org.apache.axis.client.Stub.setHeader
的方法?事情是这样的:
Maybe you can use org.apache.axis.client.Stub.setHeader
method? Something like this:
MyServiceLocator wsLocator = new MyServiceLocator();
MyServiceSoap ws = wsLocator.getMyServiceSoap(new URL("http://localhost/MyService.asmx"));
//add SOAP header for authentication
SOAPHeaderElement authentication = new SOAPHeaderElement("http://mc1.com.br/","Authentication");
SOAPHeaderElement user = new SOAPHeaderElement("http://mc1.com.br/","User", "string");
SOAPHeaderElement password = new SOAPHeaderElement("http://mc1.com.br/","Password", "string");
authentication.addChild(user);
authentication.addChild(password);
((Stub)ws).setHeader(authentication);
//now you can use ws to invoke web services...
这篇关于使用Axis 1.4设置自定义SOAP消息头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!