2011-02-23 108 views
0

我有一個SOAP,需要從Oracle調用,我聽說解決這個問題的唯一方法是通過Java類,但不幸的是,我不熟悉Java, m Oracle開發人員(Oracle Forms)我真的很感激它,如果有人能夠幫助我創建一個調用此SOAP的類,以便我可以在Oracle數據庫上構建它,並以我稱爲函數的方式從Oracle表單構建器調用它。調用SOAP的Java類 - Web服務

有兩種皁(1.1 ND 1.2),二者的任何可以工作:

* SOAP 1.1

以下是一個示例SOAP 1.1請求和響應。顯示的佔位符需要用實際值替換。

POST /gmgwebservice/service.asmx HTTP/1.1 
Host: 212.35.66.180 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://tempuri.org/SendSMS" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns: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> 
    <SendSMS xmlns="http://tempuri.org/"> 
     <UserName>string</UserName> 
     <Password>string</Password> 
     <MessageBody>string</MessageBody> 
     <Sender>string</Sender> 
     <Destination>string</Destination> 
    </SendSMS> 
    </soap:Body> 
</soap:Envelope> 
HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns: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> 
    <SendSMSResponse xmlns="http://tempuri.org/"> 
     <SendSMSResult>string</SendSMSResult> 
    </SendSMSResponse> 
    </soap:Body> 
</soap:Envelope> 

* * SOAP 1.2

以下是一個示例SOAP 1.2請求和響應。顯示的佔位符需要用實際值替換。

POST /gmgwebservice/service.asmx HTTP/1.1 
Host: 212.35.66.180 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <SendSMS xmlns="http://tempuri.org/"> 
     <UserName>string</UserName> 
     <Password>string</Password> 
     <MessageBody>string</MessageBody> 
     <Sender>string</Sender> 
     <Destination>string</Destination> 
    </SendSMS> 
    </soap12:Body> 
</soap12:Envelope> 
HTTP/1.1 200 OK 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <SendSMSResponse xmlns="http://tempuri.org/"> 
     <SendSMSResult>string</SendSMSResult> 
    </SendSMSResponse> 
    </soap12:Body> 
</soap12:Envelope> 
+1

如果調用Web服務這不是強制使用Java,你可以使用另一個langage。無論如何,如果您必須使用Java,我會建議使用CXF框架來實現此目的(請參閱http://cxf.apache.org/)。 – reef 2011-02-23 14:52:12

+0

我不知道Oracle Forms如何工作,所以也許我的問題很愚蠢。無論如何,是否有可能使用Oracle Forms開發Java代碼,我的意思是有可能擁有一個真正的Java項目?如果有可能,那麼CXF是解決方案恕我直言。 – reef 2011-02-23 15:11:25

回答

0

您可以使用各種編程語言調用SOAP方法。如果您需要在Java中執行此操作,您需要查看JAX-WSHere是在Oracle Forms Builder中使用JAX-WS的教程。要使用它,你需要Forms Builder 11g。

您向該向導提供WSDL(Web服務描述語言)文件的URL。它會引導您完成將代碼發送到SOAP服務,部署和代碼導入所需的Java代碼。

1

在Java中實現簡單的SOAP客戶端,您可以使用SAAJ框架(它是隨JSE 1.6及以上):

用於Java(SAAJ)附件API SOAP主要用於直接處理任何Web Service API中幕後發生的SOAP請求/響應消息。它允許開發人員直接發送和接收SOAP消息,而不是使用JAX-WS。

請參閱下面的使用SAAJ的SOAP Web服務調用的工作示例(運行它!)。它叫this web service

import javax.xml.soap.*; 
import javax.xml.transform.*; 
import javax.xml.transform.stream.*; 

public class SOAPClientSAAJ { 

    /** 
    * Starting point for the SAAJ - SOAP Client Testing 
    */ 
    public static void main(String args[]) { 
     try { 
      // Create SOAP Connection 
      SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); 
      SOAPConnection soapConnection = soapConnectionFactory.createConnection(); 

      // Send SOAP Message to SOAP Server 
      String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx"; 
      SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); 

      // Process the SOAP Response 
      printSOAPResponse(soapResponse); 

      soapConnection.close(); 
     } catch (Exception e) { 
      System.err.println("Error occurred while sending SOAP Request to Server"); 
      e.printStackTrace(); 
     } 
    } 

    private static SOAPMessage createSOAPRequest() throws Exception { 
     MessageFactory messageFactory = MessageFactory.newInstance(); 
     SOAPMessage soapMessage = messageFactory.createMessage(); 
     SOAPPart soapPart = soapMessage.getSOAPPart(); 

     String serverURI = "http://ws.cdyne.com/"; 

     // SOAP Envelope 
     SOAPEnvelope envelope = soapPart.getEnvelope(); 
     envelope.addNamespaceDeclaration("example", serverURI); 

     /* 
     Constructed SOAP Request Message: 
     <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/"> 
      <SOAP-ENV:Header/> 
      <SOAP-ENV:Body> 
       <example:VerifyEmail> 
        <example:email>[email protected]</example:email> 
        <example:LicenseKey>123</example:LicenseKey> 
       </example:VerifyEmail> 
      </SOAP-ENV:Body> 
     </SOAP-ENV:Envelope> 
     */ 

     // SOAP Body 
     SOAPBody soapBody = envelope.getBody(); 
     SOAPElement soapBodyElem = soapBody.addChildElement("VerifyEmail", "example"); 
     SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("email", "example"); 
     soapBodyElem1.addTextNode("[email protected]"); 
     SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LicenseKey", "example"); 
     soapBodyElem2.addTextNode("123"); 

     MimeHeaders headers = soapMessage.getMimeHeaders(); 
     headers.addHeader("SOAPAction", serverURI + "VerifyEmail"); 

     soapMessage.saveChanges(); 

     /* Print the request message */ 
     System.out.print("Request SOAP Message = "); 
     soapMessage.writeTo(System.out); 
     System.out.println(); 

     return soapMessage; 
    } 

    /** 
    * Method used to print the SOAP Response 
    */ 
    private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception { 
     TransformerFactory transformerFactory = TransformerFactory.newInstance(); 
     Transformer transformer = transformerFactory.newTransformer(); 
     Source sourceContent = soapResponse.getSOAPPart().getContent(); 
     System.out.print("\nResponse SOAP Message = "); 
     StreamResult result = new StreamResult(System.out); 
     transformer.transform(sourceContent, result); 
    } 

} 

(上面的代碼被截斷並從this page調整。)