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

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

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

    lqxue

    常用鏈接

    統計

    book

    tools

    最新評論

    java的call基于document/literal的webservice

    WSDL

    <definitions
         
    name="HelloWorld"
         targetNamespace
    ="http://xmlns.oracle.com/HelloWorld"
         xmlns
    ="http://schemas.xmlsoap.org/wsdl/"
         xmlns:plnk
    ="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
         xmlns:soap
    ="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:client
    ="http://xmlns.oracle.com/HelloWorld"
        
    >
        
    <types>
            
    <schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/HelloWorld"
                 xmlns
    ="http://www.w3.org/2001/XMLSchema">
                
    <element name="HelloWorldProcessRequest">
                    
    <complexType>
                        
    <sequence>
                            
    <element name="input" type="string"/>
                        
    </sequence>
                    
    </complexType>
                
    </element>
                
    <element name="HelloWorldProcessResponse">
                    
    <complexType>
                        
    <sequence>
                            
    <element name="result" type="string"/>
                        
    </sequence>
                    
    </complexType>
                
    </element>
            
    </schema>
        
    </types>
        
    <message name="HelloWorldRequestMessage">
            
    <part name="payload" element="client:HelloWorldProcessRequest"/>
        
    </message>
        
    <message name="HelloWorldResponseMessage">
            
    <part name="payload" element="client:HelloWorldProcessResponse"/>
        
    </message>
        
    <portType name="HelloWorld">
            
    <operation name="process">
                
    <input message="client:HelloWorldRequestMessage"/>
                
    <output message="client:HelloWorldResponseMessage"/>
            
    </operation>
        
    </portType>
        
    <binding name="HelloWorldBinding" type="client:HelloWorld">
            
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            
    <operation name="process">
                
    <soap:operation style="document" soapAction="process"/>
                
    <input>
                    
    <soap:body use="literal"/>
                
    </input>
                
    <output>
                    
    <soap:body use="literal"/>
                
    </output>
            
    </operation>
        
    </binding>
        
    <service name="HelloWorld">
            
    <port name="HelloWorldPort" binding="client:HelloWorldBinding">
                
    <soap:address location="http://robin:9700/orabpel/default/HelloWorld/1.0"/>
            
    </port>
        
    </service>
      
    <plnk:partnerLinkType name="HelloWorld">
        
    <plnk:role name="HelloWorldProvider">
          
    <plnk:portType name="client:HelloWorld"/>
        
    </plnk:role>
      
    </plnk:partnerLinkType>

    </definitions>


    Java 代碼:
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.rmi.RemoteException;
    import java.util.Vector;

    import javax.xml.namespace.QName;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.rpc.ServiceException;

    import org.apache.axis.client.Call;
    import org.apache.axis.constants.Style;
    import org.apache.axis.message.SOAPBodyElement;
    import org.apache.xml.serialize.DOMSerializerImpl;
    import org.apache.xml.serialize.OutputFormat;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;

    public class BPELServiceTest {
          
    //service的命名空間
        static final String ns = "http://xmlns.oracle.com/HelloWorld";

        
    public static void main(String args[]){
            Call call 
    = null;
            
    try {
                call 
    = createCall();
                Vector rtn 
    = (Vector) call.invoke(createRequest());
                parse(rtn);
            }
     catch (MalformedURLException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     catch (RemoteException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     catch (ParserConfigurationException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     catch (FactoryConfigurationError e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     catch (Exception e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }


          
    /*       * 創建Call對象,對設置相關屬性,注意:其中的屬性應該是通過分析WSDL文件由程序動態獲得來賦值,       * 這里全部簡化為靜態賦值       */
        
    static Call createCall() throws MalformedURLException, ServiceException{
            org.apache.axis.client.Service s 
    = new org.apache.axis.client.Service();
            Call call 
    = (Call) s.createCall();
            call.setTargetEndpointAddress(
    new URL("http://robin:9700/orabpel/default/HelloWorld/1.0"));
            call.setSOAPActionURI(
    "process");
            call.setOperationName(
    "process");
            call.setProperty(Call.OPERATION_STYLE_PROPERTY, Style.DOCUMENT.getName());
            call.setPortName(
    new QName(ns, "HelloWorldPort"));
            call.setPortTypeName(
    new QName(ns, "HelloWorld"));

            
    return call;
        }


          
    /*       *創建請求參數,實際上就是構建DOM片斷,根據Web service對輸入參數的要求來構建,要多復雜,都可以實現,       *這就是Docuemnt的好處,省去了復雜對象的序列化。       */
        
    static Object[] createRequest() throws ParserConfigurationException, FactoryConfigurationError{
            DocumentBuilder db 
    = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc 
    = db.newDocument();
            Element root 
    = doc.createElementNS(ns, "HelloWorldProcessRequest");
            Element input 
    = doc.createElementNS(ns, "input");
            input.appendChild(doc.createTextNode(
    "robin"));
            root.appendChild(input);
            doc.appendChild(root);

            
    return new Object[]{new SOAPBodyElement(root)};
        }


          
    // 對返回結果進行解析,并打印。
        static void parse(Vector v) throws Exception{
            Document doc 
    = ((SOAPBodyElement) v.get(0)).getAsDocument();
            Element root 
    = doc.getDocumentElement();
            OutputFormat of 
    = new OutputFormat();
            of.setIndent(
    4);
            System.out.println(
    new DOMSerializerImpl().writeToString(root));
        }

    }



    上述代碼運行輸出結果為:

    <?xml version="1.0"?>
    <HelloWorldProcessResponse xmlns="http://xmlns.oracle.com/HelloWorld">
    <result xmlns="http://xmlns.oracle.com/HelloWorld">robin</result>
    </HelloWorldProcessResponse>



    上面的代碼很簡單,需要說明的是:采用Document調用,實際上invoke方法的參數是一個元素類型為SOAPBodyElement的對象數組,而返回結果是一個元素類型的SOAPBodyElement的Vector對象。

     

    From:http://www.javaeye.com/topic/138876

    posted on 2008-05-26 11:09 lqx 閱讀(1540) 評論(1)  編輯  收藏 所屬分類: web service

    評論

    # re: java的call基于document/literal的webservice 2008-06-02 15:01 liguoxin

    很不錯的,不知道用java調.net寫的web service是不是也只這樣寫的。.net的web service不就是document的嗎  回復  更多評論   

    主站蜘蛛池模板: 四虎成人精品在永久免费| 麻豆国产人免费人成免费视频| 亚洲天堂中文字幕在线| 美女被艹免费视频| www.亚洲精品| 一级特黄aaa大片免费看| 亚洲av中文无码| 一个人免费观看日本www视频 | 成人亚洲国产va天堂| 成年女人毛片免费视频| 午夜亚洲国产理论片二级港台二级 | 中文字幕版免费电影网站| 亚洲人成中文字幕在线观看| 好久久免费视频高清| 亚洲系列国产精品制服丝袜第| 日韩亚洲国产高清免费视频| 亚洲色大情网站www| 波多野结衣视频在线免费观看| 国产精品免费久久久久影院| 久久精品国产69国产精品亚洲| 久久久高清日本道免费观看| 2022年亚洲午夜一区二区福利 | 日韩一级视频免费观看| 羞羞漫画页面免费入口欢迎你| 亚洲日产无码中文字幕| 91精品手机国产免费| 亚洲色大成网站www| 久久久久亚洲av毛片大| 91频在线观看免费大全| 特黄特色大片免费| 亚洲视频中文字幕在线| 国产免费av一区二区三区| 韩日电影在线播放免费版| 亚洲人成在线播放| 亚洲黄片手机免费观看| 最近中文字幕mv免费高清在线| 亚洲乱码av中文一区二区| 亚洲无av在线中文字幕| 无人在线观看免费高清视频| 成人a毛片视频免费看| 亚洲天堂一区二区三区|