java 调用C#的webservice

import java.rmi.RemoteException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class GetData {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		  String result = null;
		  try {
			String endpoint = "http://192.168.1.106/Service1.asmx?wsdl";
			  //直接引用远程的wsdl文件
			 //以下都是套路 
			  Service service = new Service();
			  Call call = (Call) service.createCall();
			  call.setTargetEndpointAddress(endpoint);
			  call.setOperationName("getLocalJson");//WSDL里面描述的接口名称
			  call.addParameter("name", org.apache.axis.encoding.XMLType.XSD_DATE,
			                javax.xml.rpc.ParameterMode.IN);//接口的参数
			  call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型  
			  
		/*	  JAVA调用NET 报服务器未能识别 HTTP 头 SOAPAction 的值,遇到这种问题时,是因为没有设SOAPAction 
			  的值,加上这行代码就可以call.setSOAPActionURI("http://tempuri.org/getLocalJson"),注意后面的Add方法哦,是方法名,一定要带哦*/
			  call.setSOAPActionURI("http://tempuri.org/getLocalJson");
			  String temp = "fangchao";
			  result = (String)call.invoke(new Object[]{temp});
			  //给方法传递参数,并且调用方法
			  System.out.println("result is "+result);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
}
	}


}

结果:result is {"country":"qingdao","leader":"wang","generals":[{"name":"zhangfei","age":12},{"name":"guanyu","age":34}]}



所需的各种jar包:

activation.jar

axis.jar

commons-discovery.jar

commons-logging-1.1.3.jar

jaxrpc.jar

mail.jar

wsdl4j-1.5.1.jar

java 调用C#的webservice,布布扣,bubuko.com

java 调用C#的webservice

上一篇:angularJs中datatable实现


下一篇:SharePoint 2013 字段属性之JSLink