2011-02-23 105 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调整。)