日期:2014-05-17  浏览次数:20834 次

Java调用.net的webservice接口,对方无法获得参数?
我这里用的是java+axis1.4开发的客户端,对方是.net服务端,调用是成功的(对方出错信息反馈回来了),但是对方打印出参数都是空的:

java:

Call call = (Call)service.createCall();
URL u = new URL(serUrl);
call.setTargetEndpointAddress(u);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/test");
call.setOperationName(new QName("http://tempuri.org/","test");

call.addParameter(new QName("http://tempuri.org/","param1"),XMLType.XSD_STRING,ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);

Object obj = call.invoke("test",new Object[]{"xxxxx"});
System.out.println(obj);

--------------对方程序
[WebService(Namespace="http://tmpuri.org/")]
...
public class....
public String test(String param1){
  if(string.IsNullOrEmpty(param1)) throw new ApplicationException("参数为空");//这句话客户端能获取到


奇怪的是我客户端的程序在其他项目中也是这么写的,而且能够正常使用,唯独这个项目不好使,请各位大侠分析一下原因,谢谢。。。。

------解决方案--------------------
http://developer.51cto.com/art/200906/131217.htm

之前做过一个,java部分的没问题,但是对方方法之前,参数上面好像要加写东西,看下上面文章。
------解决方案--------------------
不知道楼主客户端可有报什么错误?
是要实现什么功能?

你调用的时候参数是字符串还是对象等等 ?

参数应当为期设置addParameter值。

Java code
//OK
    public static void quickReg(String tel)
    {
final String wsdl = "http://localhost:8000/services/UserInfoWebService";
        Service service = new Service();
        Call call;
        try {

            call = (Call) service.createCall();
            try {
            call.setTargetEndpointAddress(new  java.net.URL(wsdl));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            call.setOperationName("quick");//WSDL里面描述的接口名称
            call.getMessageContext().setUsername("user");
            call.getMessageContext().setPassword("password");
            call.addParameter("userphone", org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);//接口的参数
            call.addParameter("checkcode", org.apache.axis.encoding.XMLType.XSD_STRING,

                    javax.xml.rpc.ParameterMode.IN);//接口的参数
            
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
            Object xml;
            try {
                xml = (Object)call.invoke(new Object[]{tel,"code"});
                //给方法传递参数,并且调用方法
                System.out.println("result is "+xml);
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

------解决方案--------------------
估计是.net的配置的问题,好好查一下吧