使用Axis 1.4设置自定义SOAP标头

我正在尝试使用Axis使用.NET 2.0 Web服务。 我使用Eclipse WST插件生成了Web服务客户端,到目前为止似乎没问题。

这里是预期的SOAP标头:

  string string   

我没有找到任何有关如何从Axis客户端配置此标头的文档。 当我使用Visual Studio C#Express 2008生成客户端时,它会生成一个名为Authentication的类,其中包含两个String属性( UserPassword ),并且所有客户端方法都接收此类的对象作为第一个参数,但Axis WS不会发生这种情况。客户。

如何在客户端调用中设置此标头?

也许你可以使用org.apache.axis.client.Stub.setHeader方法? 像这样的东西:

 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... 

如果您有一个表示带有用户标识和密码的Authentication容器的对象,您可以这样做:

 import org.apache.axis.client.Stub; //... MyAuthObj authObj = new MyAuthObj("userid","password"); ((Stub) yourServiceObject).setHeader("urn://your/name/space/here", "partName", authObj); 

我有同样的问题,并由以下的fragement解决:

 ServiceSoapStub clientStub = (ServiceSoapStub)new ServiceLocator().getServiceSoap(url); org.apache.axis.message.SOAPHeaderElement header = new org.apache.axis.message.SOAPHeaderElement("http://www.abc.com/SSsample/","AuthHeader"); SOAPElement node = header.addChildElement("Username"); node.addTextNode("aat"); SOAPElement node2 = header.addChildElement("Password"); node2.addTextNode("sd6890"); ((ServiceSoapStub) clientStub).setHeader(header);