Thursday 20 October 2016

Integrating With Fusion Application Using Services (.Net: Service Reference)


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 Service Reference 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. We can generate a proxy through the Visual Studio by creating Service Reference. To integrate with a service first generate a Service Reference, in the address field enter the URL for the WSDL of the Fusion Application Service and click "Go", in this example I used CreditRuleService. The "Namespace" entered can then be used to access the objects generated in the code. In the example case the "Namespace" entered was "FusionServiceReference". In order to call a Fusion Applications web service we need to create a binding that matches the OWSM policy that the service is secured with. In this example the service is secured with "oracle/wss_username_token_over_ssl_service_policy" OWSM policy so we create a class for the custom binding as follows:
    public class UsernameTokenOverSslBinding : CustomBinding
    {
        public override BindingElementCollection CreateBindingElements()
       {
            BindingElementCollection bindingElements = new BindingElementCollection();
            bindingElements.Add(SecurityBindingElement.CreateUserNameOverTransportBindingElement());
            MtomMessageEncodingBindingElement messageEncoding = new MtomMessageEncodingBindingElement();
            messageEncoding.MessageVersion = MessageVersion.Soap11;
            bindingElements.Add(messageEncoding);
            HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
            bindingElements.Add(transport);
            return bindingElements.Clone();
        }
    }
Do note that the binding configuration above is the minimum required for the given policy, depending on the policy additional configuration may be required.  The following is a complete example on how use the reference objects generated to find, create and delete a rule by calling a Fusion Applications Web Service:
using System;
using System.ServiceModel.Channels;
using System.ServiceModel;
using ServiceReferenceExample1Client.FusionServiceReference;

namespace ServiceReferenceExample1Client
{
    /// <summary>
    /// Custom binding that can be used to invoke Fusion Application services secured with OWSM policy
    /// </summary>
    /// <remarks>
    /// This custom binding can be used to invoke Fusion Application services secured with 
    /// "oracle/wss_username_token_over_ssl_service_policy" OWSM policy
    /// </remarks>
    public class UsernameTokenOverSslBinding : CustomBinding
    {
        public override BindingElementCollection CreateBindingElements()
        {
            BindingElementCollection bindingElements = new BindingElementCollection();
            bindingElements.Add(SecurityBindingElement.CreateUserNameOverTransportBindingElement());
            MtomMessageEncodingBindingElement messageEncoding = new MtomMessageEncodingBindingElement();
            messageEncoding.MessageVersion = MessageVersion.Soap11;
            bindingElements.Add(messageEncoding);
            HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
            bindingElements.Add(transport);
            return bindingElements.Clone();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
           
 EndpointAddress endpointAddress = new EndpointAddress(new 
Uri("https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService"));

            // Get instance of the service to be invoked
            CreditRuleServiceClient crs = new CreditRuleServiceClient(new UsernameTokenOverSslBinding(), endpointAddress);

            // Set the authentication details to be used for the service call
            crs.ClientCredentials.UserName.UserName = "username";
            crs.ClientCredentials.UserName.Password = "password";

            // Run the test case which includes queries, creates and deletes a rule
            callFindRule(crs);
            callCreateRule(crs);
            Rule rule = callFindRule(crs);
            callDeleteRule(crs, rule);
            callFindRule(crs);

        }

        /// <summary>
        /// Logic to find a object using a web service call
        /// </summary>
        /// <param name="crs">Instance of the credit rule service client</param>
        /// <returns>Rule with a given name in this case "JRAUTIAI_TEST_RULE1"</returns>
        static Rule callFindRule(CreditRuleServiceClient crs)
        {
            Rule result = null;
            try
            {
                // Populate the objects to be used as parameter
                FindCriteria findCriteria = new FindCriteria();
                ViewCriteria viewCriteria = new ViewCriteria();
                viewCriteria.conjunction = Conjunction.And;
                ViewCriteriaRow viewCriteriaRow = new ViewCriteriaRow();
                viewCriteriaRow.conjunction = Conjunction.And;
                viewCriteriaRow.upperCaseCompare = false;
                ViewCriteriaItem viewCriteriaItem = new ViewCriteriaItem();
                viewCriteriaItem.conjunction = Conjunction.And;
                viewCriteriaItem.upperCaseCompare = false;
                viewCriteriaItem.attribute = "Name";
                viewCriteriaItem.@operator = "=";
                string[] ruleNames = new string[1] { "JRAUTIAI_TEST_RULE1" };
                viewCriteriaItem.Items = ruleNames;
 
                ViewCriteriaItem[] vcis = new ViewCriteriaItem[1] { viewCriteriaItem };
                viewCriteriaRow.item = vcis;
                ViewCriteriaRow[] vcrs = new ViewCriteriaRow[1] { viewCriteriaRow };
                viewCriteria.group = vcrs;
                findCriteria.filter = viewCriteria;
 
                findCriteria.fetchStart = 0;
                findCriteria.fetchSize = -1;
                FindControl findControl = new FindControl();
 
                // Call the service with the appropriate parameters
                Rule[] rules = crs.findRule(findCriteria, findControl);
                if (null != rules && rules.Length > 0)
                {
                    result = rules[0];
                    foreach (Rule rule in rules)
                    {
                        Console.WriteLine("ruleId: " + rule.RuleId + " - orgId: " + rule.OrgId + " - name: " + rule.Name);
                    }
                }
                else
                {
                    Console.WriteLine("Rule JRAUTIAI_TEST_RULE1 not found ");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return result;
        }
 
        /// <summary>
        /// Logic to create a rule, in this case we have hard coded the content of the new rule to simplify the example
        /// </summary>
        /// <param name="crs">Instance of the credit rule service client</param>
        static void callCreateRule(CreditRuleServiceClient crs)
        {
            try
            {
                // Populate the object to be used as parameter
                Rule rule = new Rule();
                rule.EnabledFlag = true;
                rule.OrgId = 300000000678473;
                rule.OrgIdSpecified = true;
                rule.UsageId = -1001;
                rule.UsageIdSpecified = true;
                rule.StartDate = new DateTime(2012, 1, 1);
                rule.StartDateSpecified = true;
                rule.EndDate = new DateTime(2012, 1, 31);
                rule.EndDateSpecified = true;
                rule.Name = "JRAUTIAI_TEST_RULE1";
 
                // Call the service with the appropriate parameters
                Rule result = crs.createRule(rule);
                Console.WriteLine("Rule JRAUTIAI_TEST_RULE1 created ");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
 
        /// <summary>
        /// Logic to delete a specific Rule
        /// </summary>
        /// <param name="crs">Instance of the credit rule service client</param>
        /// <param name="rule">Instance of the Rule to be deleted</param>
        static void callDeleteRule(CreditRuleServiceClient crs, Rule rule)
        {
            try
            {
                // Call the service with the appropriate parameters
                crs.deleteRule(rule);
                Console.WriteLine("Rule JRAUTIAI_TEST_RULE1 deleted ");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
} 
The above code does the following:
  1. Get instance of the service reference client to be invoked using custom binding and an endpoint address
  2. Set the authentication details to be used for the service call
  3. Run the test case which includes calls to create, delete and query a rule

Summary

In this article we covered an example using Service Reference 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

No comments:

Post a Comment