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

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

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

    posts - 495,comments - 227,trackbacks - 0
    調(diào)用webservice,可以首先根據(jù)wsdl文件生成客戶端,或者直接根據(jù)地址調(diào)用,下面討論直接調(diào)用地址的兩種不同方式:axis和Soap,soap方式主要是用在websphere下

    axis方式調(diào)用:

    ?

    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方式調(diào)用

    調(diào)用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();

    ?????? }

    ?? ?}

    }

    返回一維數(shù)組時

    Parameter soapResult = soapResponse.getReturnValue();

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

    ?

    調(diào)用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-07-20 17:26 SIMONE 閱讀(10870) 評論(1)  編輯  收藏 所屬分類: JAVAJSP

    FeedBack:
    # re: Webservice調(diào)用方式:axis,soap詳解
    2007-04-24 20:15 | Bob
    謝謝,領(lǐng)了  回復  更多評論
      
    主站蜘蛛池模板: 女人18毛片免费观看| 免费观看成人久久网免费观看| 91福利免费体验区观看区| 成人午夜亚洲精品无码网站| 国产亚洲日韩一区二区三区| 一级一看免费完整版毛片| 亚洲国产人成精品| 亚洲国产天堂在线观看| 亚洲日韩乱码中文字幕| 日本v片免费一区二区三区| 亚洲国产一区二区a毛片| 久草免费手机视频| 亚洲视频在线观看免费| 84pao国产成视频免费播放| 亚洲成a人片在线网站| 特级毛片爽www免费版| 91免费国产自产地址入| 亚洲国产美女福利直播秀一区二区 | 日韩亚洲AV无码一区二区不卡 | 麻豆亚洲AV永久无码精品久久| 免费观看在线禁片| 亚洲国产精品综合福利专区| 免费无码AV电影在线观看| 亚洲最大激情中文字幕| 久久久久国色av免费看| 久久精品国产亚洲AV忘忧草18| 成人黄页网站免费观看大全| 四虎影视在线看免费观看| 国产成A人亚洲精V品无码| 18禁止观看免费私人影院| 亚洲va国产va天堂va久久| 美女黄色毛片免费看| 国产精品无码免费播放| 黄床大片30分钟免费看| 国产成A人亚洲精V品无码性色| 香蕉97超级碰碰碰免费公| 曰批全过程免费视频观看免费软件 | APP在线免费观看视频| 亚洲制服丝袜中文字幕| 亚洲国产精品日韩| 国产免费不卡视频|