Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Axis 1.4设置自定义SOAP标头_Java_.net_Web Services_Soap_Axis - Fatal编程技术网

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

Java 使用Axis 1.4设置自定义SOAP标头,java,.net,web-services,soap,axis,Java,.net,Web Services,Soap,Axis,我正在尝试使用Axis使用.NET2.0Web服务。 我使用EclipseWST插件生成了web服务客户端,到目前为止似乎还可以 这里是预期的SOAP头: <soap:Header> <Authentication xmlns="http://mc1.com.br/"> <User>string</User> <Password>string</Password> </Authentication>

我正在尝试使用Axis使用.NET2.0Web服务。 我使用EclipseWST插件生成了web服务客户端,到目前为止似乎还可以

这里是预期的SOAP头:

<soap:Header>
<Authentication xmlns="http://mc1.com.br/">
    <User>string</User>
    <Password>string</Password>
</Authentication>
</soap:Header>

一串
一串
我没有找到任何关于如何从Axis客户端配置此标头的文档。 当我使用Visual Studio C#Express 2008生成客户端时,它生成了一个名为
Authentication
的类,该类具有两个字符串属性(
User
Password
),并且所有客户端方法都会接收该类的对象作为第一个参数,但Axis WS-client没有发生这种情况


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

也许您可以使用
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...

如果您有一个用userid和password表示
身份验证
容器的对象,您可以这样做:

import org.apache.axis.client.Stub;

//...

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

我有同样的问题,通过以下方式解决:

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);

我使用了与前面提到的几乎相同的解决方案:

SOAPHeaderElement cigWsHeader = new SOAPHeaderElement("https://ws.creditinfo.com", "CigWsHeader"); cigWsHeader.addChildElement("UserName").setValue("username"); cigWsHeader.addChildElement("Password").setValue("password"); var port = new ServiceLocator().getServiceSoap(someUrl); ((Stub) port).setHeader(cigWsHeader); SOAPHeaderElement cigWsHeader=新的SOAPHeaderElement(“https://ws.creditinfo.com“,“CigWsHeader”); cigWsHeader.addChildElement(“用户名”).setValue(“用户名”); cigWsHeader.addChildElement(“密码”).setValue(“密码”); var port=new ServiceLocator().getServiceSoap(someUrl); ((存根)端口).setHeader(cigWsHeader);
并花费数小时搜索“未找到安全标头”的原因。答案是。。。命名空间处的冗余符号“/”:https://ws.creditinfo.com/" . 认真地记住这一点。

经过这么多令人沮丧的小时,这就是我需要的答案。谢谢这正是我需要的<代码>SOAPHeaderElement身份验证=新的SOAPHeaderElement(“http://mc1.com.br/“,“认证”)此语句给出了一个错误
无法启动抽象类java
如何解决此问题?如果标头有两个soapElement,该怎么办:哪种类型的对象是
MyAuthObj
?也许OP的认证是
认证
?如果是这样,客户端如何实例化这样的对象?。。。谢谢