微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

axis 提供webservice 连接.net

1)引入axis需要的所有jar包

2)开发测试:

实例一)

package testAxis;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.xml.namespace.QName;

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

public class GetIPContent
{
    private String url="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx";
    private String soapaction="http://WebXml.com.cn/";
   
    public GetIPContent()
    {
        Service service=new Service();
        try{
            Call call=(Call)service.createCall();           
            call.setTargetEndpointAddress(url);           
            call.setoperationName(new QName(soapaction,"getGeoIPContext"));
            call.setReturnType(new QName(soapaction,"getGeoIPContext"),Vector.class); 
            call.setUseSOAPAction(true);
            call.setSOAPActionURI(soapaction + "getGeoIPContext");   
            Vector v=(Vector)call.invoke(new Object[]{});//调用方法并传递参数       
            for(int i=0;i<v.size();i++)
            {
                System.out.println(v.get(i));
            }           
           
        }catch(Exception ex)
        {
        ex.printstacktrace();
        }       
    }
   
    public static void main(String args[])
    {
    GetIPContent gip=new GetIPContent();
    }
     
}

2)实例2:

package testAxis;

import java.util.Vector;

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

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

public class GetIPCountry {
  private String url="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx";
     private String soapaction="http://WebXml.com.cn/";
    
     public GetIPCountry()
     {
         Service service=new Service();
         try{
             Call call=(Call)service.createCall();           
             call.setTargetEndpointAddress(url);           
             call.setoperationName(new QName(soapaction,"getCountryCityByIp"));
           
             call.addParameter(new QName("http://WebXml.com.cn/",XMLType.XSD_STRING,ParameterMode.IN);
             call.setReturnType(new QName(soapaction,"getCountryCityByIp"),Vector.class);   
            
             call.setUseSOAPAction(true);
             call.setSOAPActionURI(soapaction + "getCountryCityByIp");   
                        
             Vector v=(Vector)call.invoke(new Object[]{"218.234.125.123"});//调用方法并传递参数       
             for(int i=0;i<v.size();i++)
             {
                 System.out.println(v.get(i));
             }           
            
         }catch(Exception ex)
         {
         ex.printstacktrace();
         }       
     }
    
     public static void main(String args[])
     {
      GetIPCountry gip=new GetIPCountry();
     }
}

3)实例三:

package testAxis;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class TestWebService {

/**
* @param args
*/
public static void main(String[] args) {
   // Todo Auto-generated method stub
   System.out.println("Start invoking....");
   try
   {
    String endPoint="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx";
    Service service = new Service();
    Call call = (Call)service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(endPoint));
    call.setoperation("getVersionTime");
    call.setUseSOAPAction(true);
    call.setSOAPActionURI("http://WebXml.com.cn/getVersionTime");  
    call.setoperationName(new QName("@L_502_7@"));     
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 
    String str=(String)call.invoke( new Object[]{});
    System.out.println(str);            
   }catch(Exception e)
   {
    e.printstacktrace();
   }  
}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐