如何封装soap消息头?--java调用webservice

jancky2001 2008-04-29 03:56:53
各位,现在有一个地址,使用。net实现的webservice的应用,我客户端用java实现,代码如下:

import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;

import javax.xml.namespace.QName;
import org.apache.axis.message.SOAPHeaderElement;
import java.util.Hashtable;
import org.apache.axis.transport.http.HTTPConstants;


public class wapwbc2 {
public static void main(String args[]) throws Exception{
String soapaction="http://www.china-call.com.cn/"; //域名,这是在server定义的

String endPoint ="http://www.china-call.com.cn/webservice/china-call.asmx?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
Object result;
try {

Hashtable myhttp = new Hashtable();
myhttp.put("UserName", "cxuser");
myhttp.put("UserPwd", "aaa");
call.setProperty(HTTPConstants.REQUEST_HEADERS, myhttp);

//call.addHeader(header);


call.setTargetEndpointAddress(new java.net.URL(endPoint));
call.setOperationName("TempReCall");
call.addParameter(new QName(soapaction,"srcPhone"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter("destPhone", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
result = (Object) call.invoke(new Object[] {"13547821035","87017730"});

System.out.println("result"+result);
}
catch (AxisFault fault) {
result = "Error is: " + fault.toString();
}
System.out.println(result);
}
}

各位可以看到,我是用axis的api来调用webservice的,但是现在有个问题。

我运行后结果如下:

Error is: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)


单步调试后执行到result = (Object) call.invoke(new Object[] {"13547821035","87017730"});
时报异常。

现在的情况时,按理说我的代码是没有问题的,服务器端加了身份验证,说的时在soap头里面带上用户名密码,我查了很多资料,都没有看到对应的解决方法,请问哪位对webservice比较熟悉的,帮我看看,我到底怎样封装我的soap消息头,才能够通过服务器端的身份验证。

谢谢兄弟们。
...全文
936 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
numen_wlm 2008-04-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jancky2001 的回复:]
晕,整个互联网的这个资料都少,郁闷了
[/Quote]
好像有很多嘛,你不要用baidu,baidu能搜到的都是国内的资料,你用google一搜一大堆,不过都是老外的东东,
要是你En还可以的话,一定能找到解决方案的.
PS:通常情况下,我的搜索顺序是先baidu(毕竟都是汉字的东西,看着方便^_^),没有好的结果的话就google,而且一定要搜老外的东西,
通常都能找到解决办法。
jancky2001 2008-04-29
  • 打赏
  • 举报
回复
晕,整个互联网的这个资料都少,郁闷了
numen_wlm 2008-04-29
  • 打赏
  • 举报
回复
有可能是你用SOAP访问webservice,并且在HTTP请求中送了一个SOAPAction的参数,但是这个参数不是service所要求的,所以你最好确定namespace是正确的,并且对照wsdl检查其参数需求...

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧