java+axis客户端调用.net服务端webservice

package com.aic.client;


import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;


import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;


public class HelloClientDotNet {


public String userValid(String username, String pwd){
//String url="http://XXX.com/Svc.asmx";  // 
String url="http://XXX.com/Service1.asmx";
String namespace = "http://tempuri.org/";   
String methodName = "CheckUserPasswd";   
String soapActionURI = "http://tempuri.org/CheckUserPasswd";   
Service service = new Service();   
Call call = null;
try {
call = (Call) service.createCall();
} catch (ServiceException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}   
try {
call.setTargetEndpointAddress(new java.net.URL(url));
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}   
call.setUseSOAPAction(true);   
//这个地方没设对就会出现Server was unable to read request的错误   
call.setSOAPActionURI(soapActionURI);   
call.setOperationName(new QName(namespace, methodName));   
/*这里如果设置成call.addParameter(new QName(namespace,"s"), XMLType.XSD_STRING,   
 ParameterMode.IN);就是调用document风格的.net服务端  
 如果设反了,.net服务端就接不到参数,接到的是null  
*/  
call.addParameter("username", XMLType.XSD_STRING, ParameterMode.IN);   
call.addParameter("passwd", XMLType.XSD_STRING, ParameterMode.IN);   
call.setReturnType(XMLType.XSD_INT);   
Integer ret = new Integer(99);
try {
ret = (Integer)call.invoke(new Object[] { username, pwd });
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}   

System.out.println("返回结果---> " + ret);  
return null;

}

public static void main(String[] args) {
String result = new HelloClientDotNet().userValid("test", "111");//测试报备 177104204123224
System.out.println(result);
}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值