学习 学习 再学习

学习才是唯一的出路

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  31 随笔 :: 1 文章 :: 8 评论 :: 0 Trackbacks

import java.net.URL;
import java.util.Vector;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.BeanSerializer;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import org.apache.soap.transport.http.SOAPHTTPConnection;
import org.apache.soap.util.xml.QName;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import oss.util.debug.LogHome;

public class GisWebService{
 
 public static String getStringGisWebService(String ajfBm, String zjfBm, String aodfBm,String zodfBm) throws Exception {
  String strUrl = "http://192.168.1.103/ctnwebgis/webgis.aspx?WSDL";
  String strTargetURL = "http://java.sun.com/xml/ns/jax-rpc/ri/config";//
  String soapAction = "http://www.my.com/Rpc1";
     URL url = new URL(strUrl);
     SOAPMappingRegistry smr = new SOAPMappingRegistry();
     BeanSerializer beanSer = new BeanSerializer();
     smr.mapTypes(Constants.NS_URI_SOAP_ENC,new QName("","Result"),null,null,beanSer);
     Call call = new Call();
     SOAPHTTPConnection st = new SOAPHTTPConnection();
     call.setSOAPTransport(st);
     call.setSOAPMappingRegistry(smr);
     call.setTargetObjectURI(strTargetURL);
     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
     call.setParams(createCondition(ajfBm,zjfBm,aodfBm,zodfBm));
     call.setMethodName("WSEncrypt"); //调用WEBSERVICE方法名
     Response resp;
     try
     {
       call.setTimeout(3000);
       resp = call.invoke(url,soapAction);
     }
     catch(SOAPException e)
     {
       throw new Exception("调用接口出错!URL="+strUrl+"\n"+e.getMessage());
     }
     LogHome.getLog().info("调用成功,开始接收返回信息!");

     return returnValue(resp);
 }
 
 public static String returnValue(Response resp) throws Exception {
  if(resp.generatedFault()) {
        Fault fault = resp.getFault();
        String code = fault.getFaultCode();
        String desc = fault.getFaultString();
        LogHome.getLog().info("Fault code:"+code+":"+desc);
        Vector v = fault.getDetailEntries();
        int cnt = v.size();
        for(int i = 0;i<cnt;i++)
        {
          Element n = (Element)v.elementAt(i);
          Node nd = n.getFirstChild();
          LogHome.getLog().info("Each element:"+n.getNodeName()+":"+nd.getNodeValue());
        }
        throw new Exception("调用接口时出错,Fault code:"+code+":"+desc);
      }
      else
      {
        Parameter ret = resp.getReturnValue();
        String returnXML = (String)ret.getValue();
        LogHome.getLog().info(returnXML);
        return returnXML;
      }
 }
 
 public static  Vector<Parameter> createCondition(String ajfBm,String zjfBm,String aodfBm,String zodfBm) {
   Vector<Parameter> params = new Vector<Parameter>();
     params.addElement(new Parameter("AjfBm",String.class,ajfBm,null));
     params.addElement(new Parameter("ZjfBm",String.class,zjfBm,null));
     params.addElement(new Parameter("AodfBm",String.class,aodfBm,null));
     params.addElement(new Parameter("ZodfBm",String.class,zodfBm,null));
     return params;
 }
 
}



J-CN工作室
www.j-cn.org
posted on 2009-10-22 07:50 铁猴 阅读(306) 评论(0)  编辑  收藏 所属分类: JAVA随记

只有注册用户登录后才能发表评论。


网站导航: