Set custom SOAP header using Axis 1.4

前端 未结 3 1092
清歌不尽
清歌不尽 2020-12-24 15:29

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.

Here the expected SOA

相关标签:
3条回答
  • 2020-12-24 16:02

    I have the same issue and solved by the below 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);
    
    0 讨论(0)
  • 2020-12-24 16:05

    If you have an object representing the Authentication container with userid and password, you can do it like so:

    import org.apache.axis.client.Stub;
    
    //...
    
    MyAuthObj authObj = new MyAuthObj("userid","password");
    ((Stub) yourServiceObject).setHeader("urn://your/name/space/here", "partName", authObj);
    
    0 讨论(0)
  • 2020-12-24 16:12

    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...
    
    0 讨论(0)
提交回复
热议问题