恳请高手指点小弟在这跪等!关于.NET的WEB服务java客户端进行调用问题(后续狂给分)
我的具体情况是这样的
技术主管给我一个webservice接口让我做,.NET服务已经做好了并经过测试成功内网访问链接是http://192.168.1.112/WSInterface/WSInterface.asmx?WSDL
具体用什么方式来进行调用没有规定,我暂用的是axis访问代码如下:
public class Test{
String endpoint = "http://192.168.1.112/WSInterface/WSInterface.asmx?WSDL ";
public Test() {
}
public static void main(String[] args){
Test test = new Test();
Object[] objparams = new Object[22]; //提供给服务的参数
for(int i = 0;i < 22;i++){ //循环附上测试数据
objparams[i] = "test data ";
}
objparams[5] = new Integer(0);//第六个是个整数
System.out.println(test.executeAdd(objparams));//调用服务并输出结果
}
public String executeAdd(Object[] params){
String exec_result = null;
try {
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName(new QName( "http://tempuri.org/ ", "Add "));
//call.setOperationName( "Add ");
//call.setUsername( "mdbq ");
//call.setPassword( "123456 ");
call.setUseSOAPAction(true);
call.setSOAPActionURI( "http://tempuri.org/Add ");
//下面是一堆参数
call.addParameter( "fbm ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "fdw ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "fdh ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "fdz ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ffzr ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ffl ",XMLType.XSD_INT,ParameterMode.IN);
call.addParameter( "fkzq ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "fgsdm ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "flx ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftel1 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftelname1 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftel2 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftelname2 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftel3 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftelname3 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftel4 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftelname4 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftel5 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftelname5 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftel6 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "ftelname6 ",XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter( "fsszd ",XMLType.XSD_STRING,ParameterMode.IN);
//设置返回类型在这里
call.setReturnType(XMLType.XSD_STRING);
//开始调用
exec_result = (String)call.invoke(params);
return exec_result;
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
return null;
}
}
}
这个web服务本身不存在访问权限,就是说代码或配置文件中没有相关的Handle或Soap头什么的来进行授权访问,我通过链接看过其中的描述符文档没有相关的SOAP头信息。但在IIS中设置了用户名密码,在访问web服务时弹出提示框要求输入用户名密码,但我在程序中加入什么才能解决IIS这种身份验证呢。
上面代码直接执行会报出401拒绝访问错误,应该是IIS中的身份验证问题:错误信息如下
AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (401)Access Denied
faultActor:
faultNode:
faultDetail:
{}:return code: 401
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html dir=ltr>
<head>
<style> a:link {font:9pt/11pt 宋体; color:FF0000} a:visited {font:9pt/11pt 宋体; color:#4e4e4e}
</style>
<META NAME="ROBOTS" CONTENT="NOINDEX">
<title>您没有权限查看该网页</title>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=gb2312">
<META NAME="MS.LOCALE" CONTENT="ZH-CN">
</head>
<body bgcolor="FFFFFF">
<table width="410" cellpadding="3" cellspacing="5">
<tr>
<td align="left" valign="middle" width="360">
<h1 style="COLOR:000000; FONT: 12pt/15pt 宋体"><!--Problem-->您没有权限查看该网页</h1>
</td>
</tr>
<tr>
<td width="400" colspan="2"> <font style="COLOR:000000; FONT: 9pt/11pt 宋体">您提供的证书没有权限查看该目录或网页。</font></td>
</tr>
<tr>
<td width="400" colspan="2"> <font style="COLOR:000000; FONT: 9pt/11pt 宋体">
<hr color="#C0C0C0" noshade>
<p>请尝试下列操作:</p>
<ul>
<li>单击<a href="javascript:location.reload()">刷新</a>按钮,并使用其他证书重试。</li>
<li>如果您确信应该能够查看该目录或网页,请与 Web 站点管理员联系,其电子邮件地址或电话号码请参阅 <script>
<!--
if (!((window.navigator.userAgent.indexOf("MSIE") > 0) && (window.navigator.appVersion.charAt(0) == "2")))
{
Homepage();
}
//-->
</script> 主页。</li>
</ul>
<h2 style="font:9pt/11pt 宋体; color:000000">HTTP 401.2 - 未授权:服务器配置问题导致登录失败<br> Internet 信息服务</h2>
<hr color="#C0C0C0" noshade>
<p>技术信息(支持个人)</p>
<ul>
<li>背景:<br>通常,这是由于服务器端脚本未能正确发送 WWW 身份验证头文件字段。如果要通过 Active Server Pages 脚本完成此项任务,可使用“Response”对象的“AddHeader”方法来要求客户端用特定身份验证方法访问资源。
<p>
<li>详细信息:<br><a href="http://www.microsoft.com/ContentRedirect.asp?prd=iis&sbp=&pver=5.0&pid=&ID=401.2&cat=web&os=&over=&hrd=&Opt1=&Opt2=&Opt3=" target="_blank">Microsoft 支持</a>
</li>
</p>
</ul>
</font></td>
</tr>
</table>
</body>
</html>
{http://xml.apache.org/axis/}HttpErrorCode:401
(401)Access Denied
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at hw.ClientHandleServiceImpl.executeAdd2(ClientHandleServiceImpl.java:180)
at hw.ClientHandleServiceImpl.main(ClientHandleServiceImpl.java:66)
代码中我已经加了call.setUsername( "mdbq ");call.setPassword( "123456 ");但是不起作用,还是恳请高手指点,小弟在这跪等!
[解决办法]
不懂,up
[解决办法]
我也不懂!帮你顶上去!
[解决办法]
call.setUsername( "aaaa ");
call.setPassword( "12345678 ");
call.getMessageContext().setUsername( "aaaa ");
call.getMessageContext().setPassword( "12345678 ");
还有这种方法
call.setUsername( "aaaa ");
call.setPassword( "12345678 ");
call.setProperty(wWsseClientHandler.PASSword_OPTION,WsseClientHandler.PASSword_DIGEST_WITH_NONCE);
call.setClientHandlers(new WsseClientHandler(), null);
我也遇到同样的问题,这些我在试,提供一些参考给你,试出来也发布上来