ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美亚洲自偷自偷,中文字幕一区二区三区在线不卡,粉嫩欧美一区二区三区http://www.aygfsteel.com/robin/category/6613.htmlzh-cnTue, 27 Feb 2007 20:36:45 GMTTue, 27 Feb 2007 20:36:45 GMT60 JavaScript调用Web servicehttp://www.aygfsteel.com/robin/archive/2006/01/05/26773.html人生是由回忆¾l„成çš?/dc:creator>人生是由回忆¾l„成çš?/author>Thu, 05 Jan 2006 12:01:00 GMThttp://www.aygfsteel.com/robin/archive/2006/01/05/26773.htmlhttp://www.aygfsteel.com/robin/comments/26773.htmlhttp://www.aygfsteel.com/robin/archive/2006/01/05/26773.html#Feedback0http://www.aygfsteel.com/robin/comments/commentRss/26773.htmlhttp://www.aygfsteel.com/robin/services/trackbacks/26773.html要调用的Web服务是求两个整数和,òq¶è¿”回结果ã€?BR>
服务的WSDLæ–‡äšg内容如下åQ?BR>
<?xml version="1.0" encoding="utf-8" ?> 
<wsdl:definitions
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:s="http://www.w3.org/2001/XMLSchema" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:tns="http://tempuri.org/"  
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" 
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" 
    targetNamespace="http://tempuri.org/" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
     <s:schema elementFormDefault="qualified"  
        targetNamespace="http://tempuri.org/">
        <s:element name="AddTwoIntegers">
            <s:complexType>
               <s:sequence>  
                  <s:elementminOccurs="1" maxOccurs="1" name="IntegerOne" type="s:int" />    
                  <s:elementminOccurs="1" maxOccurs="1" name="IntegerTwo" type="s:int" />   
               </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="AddTwoIntegersResponse">
            <s:complexType>
                <s:sequence> 
                   <s:elementminOccurs="1" maxOccurs="1" name="AddTwoIntegersResult" type="s:int" />    
                </s:sequence>
            </s:complexType>
        </s:element>
     </s:schema>
  </wsdl:types>
  <wsdl:message name="AddTwoIntegersSoapIn"> 
      <wsdl:part name="parameters" element="tns:AddTwoIntegers" />
  </wsdl:message>
  <wsdl:message name="AddTwoIntegersSoapOut">  
      <wsdl:part name="parameters" element="tns:AddTwoIntegersResponse" />   
   </wsdl:message>
   <wsdl:portType name="SimpleServiceSoap">
       <wsdl:operation name="AddTwoIntegers">
          <wsdl:input message="tns:AddTwoIntegersSoapIn" />
          <wsdl:output message="tns:AddTwoIntegersSoapOut" />    
       </wsdl:operation> 
   </wsdl:portType>

   <wsdl:binding name="SimpleServiceSoap" type="tns:SimpleServiceSoap"> 
       <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
       <wsdl:operation name="AddTwoIntegers">   
           <soap:operation soapAction="http://tempuri.org/AddTwoIntegers" style="document" /> 
           <wsdl:input>  
               <soap:body use="literal" />    
           </wsdl:input>
           <wsdl:output>  
               <soap:body use="literal" />    
           </wsdl:output>
       </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="SimpleService"> 
      <documentation xmlns="http://schemas.xmlsoap.org/wsdl/" /> 
      <wsdl:port name="SimpleServiceSoap" binding="tns:SimpleServiceSoap">  
          <soap:address location="http://localhost/Develop.NET/Home.Develop.WebServices/SimpleService.asmx"/>  
      </wsdl:port>  
  </wsdl:service> 
</wsdl:definitions>


javaScript代码中利用了MSçš„HTTP代理对象XMLHTTP,在Mozilla's Web brower中相应的¾l„äšg是XMLHttpRequest,他们都提供了¾cÖM¼¼çš„æ–¹æ³•来完成soapè¯äh±‚。下面的代码用的是IE中的XMLHTTP对象。代码假定调用过½E‹ä¸­æ²¡æœ‰Faultã€?BR>
function fncAddTwoIntegers(a, b)
{    
    var oXmlHttp = new ActiveXObject("MSXML2.XMLHTTP");      
    oXmlHttp.open("POST", "http://localhost/Develop.NET/Home.Develop.WebServices/SimpleService.asmx'", false);
    oXmlHttp.setRequestHeader("Content-Type", "text/xml");    
    oXmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/AddTwoIntegers");

    oXmlHttp.send("      
<soap:Envelopexmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body> <AddTwoIntegersxmlns='http://tempuri.org/'> <IntegerOne>" + a + "</IntegerOne> <IntegerTwo>" + b + "</IntegerTwo> </AddTwoIntegers>
</soap:Body> </soap:Envelope>"); return oXmlHttp.responseXML.selectSingleNode("http://AddTwoIntegersResult").text; }


åŽŸæ–‡è‹±æ–‡å‡ø™‡ªåQ?A target=_blank>http://builder.com.com/5100-6371_14-5887775.html?tag=nl.e601

]]>
用Document/literal方式调用web servicehttp://www.aygfsteel.com/robin/archive/2006/01/02/26385.html人生是由回忆¾l„成çš?/dc:creator>人生是由回忆¾l„成çš?/author>Mon, 02 Jan 2006 14:09:00 GMThttp://www.aygfsteel.com/robin/archive/2006/01/02/26385.htmlhttp://www.aygfsteel.com/robin/comments/26385.htmlhttp://www.aygfsteel.com/robin/archive/2006/01/02/26385.html#Feedback2http://www.aygfsteel.com/robin/comments/commentRss/26385.htmlhttp://www.aygfsteel.com/robin/services/trackbacks/26385.htmlDocument方式是Web service¾~ºçœè°ƒç”¨æ¨¡å¼åQŒå’Œliteral相组合,¾l™æˆ‘们调用Web service提供了极大的便利åQŒçœåŽÖMº†RPC调用方式的复杂类型序列化的问题,所以,Doucment调用方式在BPEL领域应用非常òq¿æ³›åQŒä¸‹é¢ä»‹¾låŸºäºŽAxis利用Document方式来调用一个Web service.

1. Web service准备åQ?BR>Web service你可以ä“Q意实çŽîC¸€ä¸ªï¼Œæˆ‘是利用Oracle BPEL,通过建立一个BPEL‹¹ç¨‹åQŒç„¶åŽæŠŠå®ƒå‘å¸ƒäØ“Web service(具体创徏˜q‡ç¨‹çœç•¥åQ‰ï¼Œ˜q™é‡Œé‡è¦çš„æ˜¯Web serviceçš„WSDLæ–‡äšgåQŒè¿™æ˜¯æˆ‘们调用的门户ã€?BR>下面是我的Web serviceçš„WSDLæ–‡äšg内容åQ?BR>
<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>


2. ¾~–写调用¾c?代码如下åQ?BR>
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对象åQŒå¯¹è®„¡½®ç›¸å…³å±žæ€§ï¼Œæ³¨æ„åQšå…¶ä¸­çš„属性应该是通过分析WSDLæ–‡äšgç”Þq¨‹åºåŠ¨æ€èŽ·å¾—æ¥èµ‹å€û|¼Œ
* ˜q™é‡Œå…¨éƒ¨½Ž€åŒ–äØ“é™æ€èµ‹å€?BR> */ 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; } /*
       *创徏è¯äh±‚参数åQŒå®žé™…上ž®±æ˜¯æž„徏DOM片断åQŒæ ¹æ®Web service对输入参数的要求来构建,要多复杂åQŒéƒ½å¯ä»¥å®žçްåQ?BR> *˜q™å°±æ˜¯Docuemnt的好处,省去了复杂对象的序列化ã€?BR> */ 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)}; } // 对返回结果进行解析,òq¶æ‰“印ã€? 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)); } }


上述代码˜qè¡Œè¾“出¾l“果为:
<?xml version="1.0"?>
<HelloWorldProcessResponse xmlns="http://xmlns.oracle.com/HelloWorld">
   <result xmlns="http://xmlns.oracle.com/HelloWorld">robin</result>
  </HelloWorldProcessResponse>


上面的代码很½Ž€å•,需要说明的是:采用Document调用åQŒå®žé™…上invokeæ–ÒŽ³•çš„å‚æ•°æ˜¯ä¸€ä¸ªå…ƒç´ ç±»åž‹äØ“SOAPBodyElement的对象数¾l„,而返回结果是一个元素类型的SOAPBodyElementçš„Vector对象ã€?/DIV>

]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º ÄϾ©ÊÐ| Áúº£ÊÐ| ¸®¹ÈÏØ| ¹þ°ÍºÓÏØ| èëµéÊÐ| ºø¹ØÏØ| äÒÖÐÏØ| ÀûÐÁÏØ| ÌìÕòÏØ| ¹þÃÜÊÐ| ÑîÆÖÇø| Ë«·åÏØ| ÖζàÏØ| ÍпËÑ·ÏØ| Çຣʡ| ×óÈ¨ÏØ| ÁÙÈªÏØ| Í­¹ÄÏØ| »´°²ÊÐ| È«½·ÏØ| ËÞÖÝÊÐ| ¹®ÁôÏØ| Ò¶³ÇÏØ| ÉÛÑôÊÐ| Ô˳ÇÊÐ| µÂÇÕÏØ| ÓãÌ¨ÏØ| ÓÀÐÞÏØ| Ïâ»ÆÆì| ¹ðƽÊÐ| ÏÉÓÎÏØ| ¸Ê¹ÈÏØ| Æ½ÒØÏØ| ÁÚË®| ÍôÇåÏØ| êùÎªÏØ| ÔÀÆÕºþÏØ| ÎÚÀ­ÌغóÆì| ºÓ±±Çø| ËÞÖÝÊÐ| »ÝÖÝÊÐ|