.NET Framework
Use the various features of .NET framework to integrate with the web services in Oracle Applications Cloud.
HttpWebRequest
Use HttpWebRequest to programmatically construct the SOAP envelope and invoke the web service. This Web Proxy approach hides much of the complexity and provides convenience methods, instead of hand-crafting the XML. Some cases may require direct calls with HttpWebRequest. For such cases, the following is an example of a http request to:
-
Construct an xml payload to invoke the service. This example code passes a hard coded string, which is encoded to UTF-8 byte array, to the request.
-
Construct a Base64-encoded string for the credentials of the service call.
-
Create HttpWebRequest connection to the service.
-
Configure the request content type to be
xml
, HTTP method toPOST
, and set the content length. -
Configure the request to use basic authentication, with Base64-encoded user name and password, to invoke the service.
-
Set the
SOAPAction
to be invoked. Though the service call works without this value, it is a recommended standard. -
Write the xml payload to the request.
-
Get the response and process it. This example just prints the response.
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 to invoke the service. In this example, 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 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 base64 encoded user name and 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 as per 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);
}
}
}
Service Reference
Use Microsoft Visual Studio to create Service Reference and generate a proxy that can invoke web services.
To integrate with a service, first generate a Service Reference and then use the specified service reference name to access the objects generated in the code. In the following example, FusionServiceReference is the service reference name. This example shows how to use a generated reference object to find, create, and delete a rule by calling a 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);
}
}
}
}