<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    danchaofan

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      14 Posts :: 20 Stories :: 3 Comments :: 0 Trackbacks
    調用webservice,可以首先根據wsdl文件生成客戶端,或者直接根據地址調用,下面討論直接調用地址的兩種不同方式:axis和Soap,soap方式主要是用在websphere下

    axis方式調用:

     

    import java.util.Date;

    import java.text.DateFormat;

    import org.apache.axis.client.Call;

    import org.apache.axis.client.Service;

    import javax.xml.namespace.QName;

    import java.lang.Integer;

    import javax.xml.rpc.ParameterMode;

     

    public class caClient {

                

           public static void main(String[] args) {

     

                  try {

                         String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";

                         Service service = new Service();

                         Call call = (Call) service.createCall();

                         call.setTargetEndpointAddress(endpoint);

                         call.setOperationName("addUser");

                         call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,

                                       javax.xml.rpc.ParameterMode.IN);

                         call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

                         call.setUseSOAPAction(true);

                         call.setSOAPActionURI("http://www.my.com/Rpc");

                         //Integer k = (Integer) call.invoke(new Object[] { i, j });

                         //System.out.println("result is  " + k.toString() + ".");

                         String temp = "測試人員";

                         String result = (String)call.invoke(new Object[]{temp});

                         System.out.println("result is "+result);

                  }

                  catch (Exception e) {

                         System.err.println(e.toString());

                  }

           }

    }

    soap方式調用

    調用java生成的webservice

    import org.apache.soap.util.xml.*;

    import org.apache.soap.*;

    import org.apache.soap.rpc.*;

     

    import java.io.*;

    import java.net.*;

    import java.util.Vector;

     

    public class caService{

           public static String getService(String user) {

           URL url = null;

           try {

               url=new URL("http://192.168.0.100:8080/ca3/services/caSynrochnized");

           } catch (MalformedURLException mue) {

              return mue.getMessage();

             }

                 // This is the main SOAP object

           Call soapCall = new Call();

           // Use SOAP encoding

           soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

           // This is the remote object we're asking for the price

           soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");

           // This is the name of the method on the above object

           soapCall.setMethodName("getUser");

           // We need to send the ISBN number as an input parameter to the method

           Vector soapParams = new Vector();

     

           // name, type, value, encoding style

           Parameter isbnParam = new Parameter("userName", String.class, user, null);

           soapParams.addElement(isbnParam);

           soapCall.setParams(soapParams);

           try {

              // Invoke the remote method on the object

              Response soapResponse = soapCall.invoke(url,"");

              // Check to see if there is an error, return "N/A"

              if (soapResponse.generatedFault()) {

                  Fault fault = soapResponse.getFault();

                 String f = fault.getFaultString();

                 return f;

              } else {

                 // read result

                 Parameter soapResult = soapResponse.getReturnValue ();

                 // get a string from the result

                 return soapResult.getValue().toString();

              }

           } catch (SOAPException se) {

              return se.getMessage();

           }

        }

    }

    返回一維數組時

    Parameter soapResult = soapResponse.getReturnValue();

    String[] temp = (String[])soapResult.getValue();

     

    調用ASP.Net生成的webservice

    private String HelloWorld(String uri, String u) {

                  try {

                         SOAPMappingRegistry smr = new SOAPMappingRegistry();

                         StringDeserializer sd = new StringDeserializer();

                         ArraySerializer arraySer = new ArraySerializer();

                         BeanSerializer beanSer = new BeanSerializer();

                         smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(

                                       "http://tempuri.org/", "HelloWorldResult"), String.class,

                                       null, sd);

                         smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(

                                       "http://tempuri.org/", "temp"), String.class,

                                       beanSer, beanSer);

     

                         URL url = new URL(uri);

                         Call call = new Call();

                         call.setSOAPMappingRegistry(smr);

                         call.setTargetObjectURI("urn:xmethods-Service1");

                         call.setMethodName("HelloWorld");

                         call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

     

                         Vector soapParams = new Vector();

                         soapParams.addElement(new Parameter("temp", String.class, u, null));

                         call.setParams(soapParams);

     

                         Response soapResponse = call.invoke(url,"http://tempuri.org/HelloWorld");

     

                         if (soapResponse.generatedFault()) {

                                Fault fault = soapResponse.getFault();

                                System.out.println(fault);

                         } else {

                                Parameter soapResult = soapResponse.getReturnValue();

                                Object obj = soapResult.getValue();

                                System.out.println("===" + obj);

                         }

                  } catch (Exception e) {

                         e.printStackTrace();

                  }

                  return null;

           }
    posted on 2006-02-27 13:46 單炒飯 閱讀(1081) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产精品亚洲美女久久久| 国产91色综合久久免费| 波多野结衣中文一区二区免费 | 亚洲色欲色欲www在线播放 | 特级毛片全部免费播放a一级| 波多野结衣久久高清免费 | a毛片在线免费观看| 亚洲乱码精品久久久久..| 中文字幕av免费专区| 久久亚洲精品成人综合| 亚洲免费在线播放| 亚洲一区免费观看| 99久久久国产精品免费无卡顿| 亚洲综合激情视频| 成人片黄网站A毛片免费| 亚洲欧美日韩中文字幕在线一区| 国产精品无码一区二区三区免费| 亚洲AV无码一区二区三区鸳鸯影院| 免费人成网站在线高清| a毛片免费播放全部完整| 亚洲精品无码久久毛片波多野吉衣| 久草视频在线免费| 美女黄网站人色视频免费| 国产亚洲精品无码拍拍拍色欲| 女同免费毛片在线播放| 2020国产精品亚洲综合网| 日韩亚洲国产二区| 久久久久久久99精品免费 | 亚洲国产成人久久精品app| 妞干网免费视频观看| 免费无码AV一区二区| 亚洲欧洲日产国产综合网| www.黄色免费网站| 一级做a爰片久久免费| 亚洲专区在线视频| 成年女人永久免费观看片| 免费一区二区无码东京热| 亚洲中文字幕一二三四区| 亚洲毛片αv无线播放一区| 最近2019中文字幕免费看最新| 一级做a爰片性色毛片免费网站|