Java调用.NET WebService

加依赖

20211217090731001

下面两个jar包,一个在maven依赖库中没找到,一个是阿里镜像库中没有,所以需要自己下载一下。

20211217090731002

调用

20211217090731003

上面参数对应下面

20211217090731004

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
try {
String varname="成功访问!!!";
String endpoint="http://81.70.35.77:8088/TestWebService.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://tempuri.org/", "HelloWorld"));
call.addParameter(new QName("http://tempuri.org/","str"),
org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/HelloWorld");
String output=(String)call.invoke(new Object[]{ varname });
System.out.println( "result is —————— " + output.toString() + ".");
}
catch (Exception e) {
System.err.println(e.toString());
}