Integrating With Fusion Application Using Services (.Net: HttpWebRequest)

Fusion Applications provides Web services that allow external systems to integrate with Fusion Applications. There are two types of services: ADF services and composite services. ADF services are created for a logical business object and provide functionality to access and manipulate these objects. The composite services are mostly process oriented and provide an orchestration of multiple steps. 

Information about the web services provided by Fusion Applications is hosted in Oracle Enterprise Repository (OER). The information provided by OER can be used to understand the functionality provided by the service and how the service can be called.

This series of articles describes how one can invoke SOAP web services provided by Fusion Applications using various technologies. In this article we will cover how to invoke a Fusion Application web service using HttpWebRequest for .Net framework.

Prerequisites

.Net development tool such as Visual Studio 2012 needs to be installed and configured

Implementing Web Service Call

.Net framework is a software framework for Microsoft Windows commonly used by the customers. With HttpWebRequest we are programmatically construct the SOAP envelope used for invoking the service and processing the result. Generally the Web Proxy approach below is preferable as it hides much of the complexity and provides convenience methods instead of handcrafting the XML. There may be some cases where direct calls with HttpWebRequest are needed; for such cases here is an example of a http request using .Net framework:

using System;
using System.Text;
using System.Net;
using System.IO;
using System.Xml.Linq;
 
namespace HttpWebRequestExample1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Construct xml payload, which is used to invoke the service. In the example case it is a "hard coded" string.
            string envelope = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                                             "xmlns:xsi=\"http ://www.w3.org/2001/XMLSchema-instance\" " +
                                             "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
                                   "<soap:Body>" +
                                       "<findRule xmlns=\"http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/types/\">" +
                                           "<findCriteria>" +
                                               "<fetchStart xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">0</fetchStart>" +
                                               "<fetchSize xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">-1</fetchSize>" +
                                               "<filter xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">" +
                                                   "<group>" +
                                                        "<upperCaseCompare>false</upperCaseCompare>" +
                                                        "<item>" +
                                                            "<upperCaseCompare>false</upperCaseCompare>" +
                                                            "<attribute>RuleId</attribute>" +
                                                            "<operator>=</operator>" +
                                                            "<value>300000000851162</value>" +
                                                        "</item>" +
                                                   "</group>" +
                                               "</filter>" +
                                               "<excludeAttribute xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">false</excludeAttribute>" +
                                           "</findCriteria>" +
                                           "<findControl>" +
                                               "<retrieveAllTranslations xmlns=\"http://xmlns.oracle.com/adf/svc/types/\">false</retrieveAllTranslations>" +
                                           "</findControl>" +
                                       "</findRule>" +
                                   "</soap:Body>" +
                               "</soap:Envelope>";
            byte[] byteArray = Encoding.UTF8.GetBytes(envelope);
 
            // Construct the base 64 encoded string used as the credentials for the service call
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes("username" + ":" + "password");
            string credentials = System.Convert.ToBase64String(toEncodeAsBytes);
 
            // Create HttpWebRequest connection to the service
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService");
 
            // Configure the request content type to be xml, HTTP method to be POST and set the content length
            request.Method = "POST";
            request.ContentType = "text/xml;charset=UTF-8";
            request.ContentLength = byteArray.Length;
 
            // Configure the request to use basic authentication, with base 64 encoded a user name and a password to invoke the service.
            request.Headers.Add("Authorization", "Basic " + credentials);
 
            // Set the SOAP action to be invoked; while the call works without this the value is expected to be set based on standards
            request.Headers.Add("SOAPAction", "http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/findRule");
 
            // Write the xml payload to the request.
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
 
            // Get the response and process it, in this example we simply print out the response
            XDocument doc;
            using (WebResponse response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    doc = XDocument.Load(stream);
                }
           }
            Console.WriteLine(doc);
        }
    }
}

The above code does the following:

  1. Construct xml payload, which is used to invoke the service. In the example case it is a "hard coded" string which is encoded to UTF-8 byte array to be passed to the request.
  2. Construct the base 64 encoded string used as the credentials for the service call
  3. Create HttpWebRequest connection to the service
  4. Configure the request content type to be xml, HTTP method to be POST and set the content length
  5. Configure the request to use basic authentication, with base 64 encoded a user name and a password to invoke the service.
  6. Set the SOAP action to be invoked; while the call works without this the value is expected to be set based on standards
  7. Write the xml payload to the request
  8. Get the response and process it, in this example we simply print out the response

Summary

In this article we covered an example using HttpWebRequest for .Net framework to integrate with Fusion Applications using web services. In future articles other technologies for invoking Fusion Applications web services will be covered.

References

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow us on twitter Fusion Applications Extensibility, Customizations and Integration forum Fusion Applications Dev Relations YouTube Channel
This blog offers news, tips and information for developers building extensions, customizations and integrations for Oracle Fusion Applications.

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
4
5
6
8
9
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today