java calls C# webservice

java calls webservice asmx of C#

spare!

 

import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class Test {

public static void test() {
String url = "http://113.108.79.129:1126/GetInfo.asmx";
String namespace = "http://tempuri.org/";
String methodName = "GetCommAuthor";
String soapActionURI = "http://tempuri.org/GetCommAuthor";

Service service = new Service();
Call call;
try {
call = (Call) service.createCall();

call.setTargetEndpointAddress(url);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.setOperationName(new QName(namespace, methodName));

call.addParameter(new QName(namespace, "randkey"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName(namespace, "hashval"), XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);

String[] str = new String[2];
str[0] = "1234";
str[1] = "F84E09578B22FD015E6A6B47999FBCE1C6D4E90F";

Object obj = call.invoke(str);
System.out.println(obj);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
Test.test();
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324970976&siteId=291194637