java调用.net的WS,参数无法读取到
如题,我把c#写的WS代码贴出来
[SoapRpcMethod(Action = "http://www.56rh.com/WS/getName", RequestNamespace = "http://www.56rh.com/WS/", ResponseNamespace = "http://www.56rh.com/WS/", Use = System.Web.Services.Description.SoapBindingUse.Literal)]
[WebMethod(Description = "")]
public string getName(string name)
{
writefile(name);
return "Hello" + name;
}
我写了这个简单的例子,writefile为读取参数写入本地txt,java端调用我WS始终返回hello.查看txt显示参数name为空。
有人遇到过这样的情况么
[解决办法]
累不累啊?
你可以先写一个ashx,例如
<%@ WebHandler Language="C#" Class="HelloJava" %>
using System;
using System.Web;
public class HelloJava : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello " + context.Request.QueryString["name"]);
}
public bool IsReusable
{
get
{
return false;
}
}
}
String endPoint = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endPoint);
String namespace = "http://WebXml.com.cn/";
call.addParameter(new QName(namespace, "mobileCode"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName(namespace, "userID"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnClass(java.lang.String.class);
String oName = "getMobileCodeInfo";
call.setUseSOAPAction(true);
call.setSOAPActionURI(namespace + oName);
call.setOperationName(new QName(namespace, oName));
Object[] params = new Object[] {"13899900000", ""};
String result = (String) call.invoke(params);
System.out.println(result);