.net java webservice null,【 解决:java webservice调用net 参数回到NULL 】

今天为了java webservice 为了调用NET,真是累死了,搞了整整一天.最后才搞定.唉,在网上搜了半天的资料,没有一个提供了正确的答案,都是抄来抄去的,或者高手们都太低调了,经验没有共享出来.!一想到花了一天的时间

搞这,心里真的不爽哦.不过开心的是,还是搞了出来.为了让以后学JAVA的朋友少找弯路,少花时间,我把心得写出来

JAVA 代码:

public static void main(String[] args) throws Exception {

String a = "a";

String endpoint = "http://192.168.0.101/ttt/WebService1.asmx

";

// 创建一个服务(service)调用(call)

Service service = new Service();

Call call = (Call) service.createCall();// 通过service创建call对象

// 设置service所在URL

call.setTargetEndpointAddress(new java.net.URL(endpoint));

call.setOperationName(new QName("http://tempuri.org/

","Add"));

//Add 是net 那边的方法 "http://tempuri.org/

" 这个也要注意Namespace 的地址,不带也会报错

call.addParameter(new QName("http://tempuri.org/

","test"),

org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

// 这就是我搞了一天的原因所在,"test" 这个就是传参数的变量,也就是NET方面的参数,一定不要带错了

// 我当初不知道 ,以为这个参数是自己随便写的,结果总是报NULL,真是气死人了

call.setUseSOAPAction(true);

call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); //返回参数的类型

call.setSOAPActionURI("http://tempuri.org/

Add"); //这个也要注意 就是要加上要调用的方法Add,不然也会报错

// Object 数组封装了参数,参数为"This is Test!",调用processService(String arg)

String ret = (String) call.invoke(new Object[] {a});

System.out.println("--------"+ret);

}

以下是NET代码,完全为大家服务

[WebService(Namespace = "http://tempuri.org/

")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。

// [System.Web.Script.Services.ScriptService]

public class WebService1 : System.Web.Services.WebService

{

[WebMethod]

public string Add(string test)

{

test = test;

return test;

}

[WebMethod]

public string test()

{

string temp = "10";

return temp;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值