webservice的java调用
import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import org.apache.axis.constants.Use;
import org.apache.axis.constants.Style;
import javax.xml.namespace.QName;
import java.net.URLDecoder;
//正式代码
String Msg = "测试短信";
String JsNo = “10086”;
Service service = new Service();
Call call = (Call) service.createCall();
//设置地址 注意这里的地址是附带WSDL的
call.setTargetEndpointAddress(new java.net.URL(properties.getString("url")));
//设置要执行的方法 命名空间 方法名
call.setOperationName(new QName("http://tempuri.org/", "JWSend"));
//java调用.net的webservice需要设置soapaction 否则会报错
call.setProperty("javax.xml.rpc.soap.http.soapaction.use", new Boolean(true));
call.setOperationStyle(Style.WRAPPED);
call.setOperationUse(Use.LITERAL);
//设置要传入参数
//public string JWSend(string Msg,string JsNo)
//发送短消息的内容 一定要设置qname 否则soapaction识别不出来
call.addParameter(new QName("http://tempuri.org/", "Msg"), org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
//接收方的手机号码
call.addParameter(new QName("http://tempuri.org/", "JsNo"), org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.setUseSOAPAction(true);
//参数为命名空间/方法名字
call.setSOAPActionURI("http://tempuri.org/JWSend");
//设置返回的类型
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
//执行,调用webservice
String result = (String) call.invoke(new Object[]{Msg ,JsNo});
网上方法很多,主要是调用.net的webservice踩的一些坑希望对大家有用。