Java调用.net的webservice,我的java ide是NetBeans,要调用
新建一个java页面写下如下代码!
try {
Integer i = new Integer(1);
Integer j = new Integer(2);
String endpoint="http://localhost:49573/WebService1.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://localhost:49573/WebService1.asmx","IntAdd"));
call.addParameter("a",org.apache.axis.encoding.XMLType.XSD_INT,javax.xml.rpc.ParameterMode.IN);
call.addParameter("b",org.apache.axis.encoding.XMLType.XSD_INT,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
Integer k = (Integer)call.invoke(new Object[]{i,j});
JOptionPane.showMessageDialog(null,k.toString());
}
catch (Exception e) {System.err.println(e.toString());}
然后建立一个.net的webservice项目,添加如下代码
/// <summary>
/// WebService1 的摘要说明
/// </summary>
///
[WebService(Namespace = "http://localhost:49573/WebService1.asmx")]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
[ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int IntAdd(int a, int b)
{
return a + b;
}
}
现在调用可以开始了.可是我发现参数a和b的值传不到.net webservice中.不知道为什么.传过去.a和b都是0 !
请教各位!