关于java调用c#webservice参数传递为空问题解决
通过Myeclipse10.0 jdk1.7调用VS2012 webService遇到java客户端参数传递不过去的问题,搞了一下午终于出结果了,其实网上好多方法都只是一部分,需要综合一下。
客户端我是用import org.apache.axis.client.Call;方法调用服务成功解决该问题的的,通过RPCServiceClient以及axis2自动生成的stub调用均未找到合适的传递参数的方法
client:
import
java.net.MalformedURLException;
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;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class test4 {
public static void main(String[] args) throws RemoteException, MalformedURLException, ServiceException {
String service_url = "http://localhost:30332/WebService1.asmx";
Service ser = new Service();
Call call = (Call) ser.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));
QName opAddEntry = new QName("http://tempuri.org/", "HelloWorld");
call.setOperationName(opAddEntry);
call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING); Object[] opAddEntryArgs = new Object[] { "jone" };
String result = (String) call.invoke(opAddEntryArgs);
call.invoke("http://tempuri.org/", "HelloWorld", opAddEntryArgs);
System.out.println("result:" + result);
}
}
服务端:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Diagnostics;
namespace WebApplication1
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public class WebService1 : System.Web.Services.WebService
{
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/HelloWord", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
[WebMethod]
public