.NET Framework
.NET Frameworkの様々な機能を使用すると、Oracle Applications CloudのWebサービスと統合できます。
HttpWebRequest
HttpWebRequestを使用してSOAPエンベロープをプログラムによって構成し、Webサービスを呼び出します。 このWebプロキシによるアプローチは、複雑さの大部分を隠し、XMLを手動で作成するかわりに便利な方法を提供します。 HttpWebRequestを使用した直接呼出しが必要になる場合もあります。 その場合のhttp要求の例は次のとおりです。
-
サービスを呼び出すxmlペイロードを作成します。 このコード例は、ハードコードされた文字列(UTF-8バイト配列にエンコード)を要求に渡します。
-
サービス・コールの資格証明のため、Base 64でエンコードされた文字列を作成します。
-
サービスへのHttpWebRequest接続を作成します。
-
要求のコンテンツ・タイプを
xml
に、HTTPメソッドをPOST
に構成し、コンテンツの長さを設定します。 -
サービスを呼び出すため、Base64でエンコードされたユーザー名とパスワードを指定して、基本認証を使用するように要求を構成します。
-
呼び出す
SOAPAction
を設定します。 サービス・コールはこの値がなくても行えますが、これが推奨される標準です。 -
xmlペイロードを要求に書き込みます。
-
応答を取得して処理します。 この例は、応答を単に出力します。
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);
}
}
}
サービス参照
Microsoft Visual Studioを使用して、サービス参照を作成し、Webサービスを呼び出すプロキシを生成します。
サービスと統合するには、まずサービス参照を生成し、指定したサービス参照名を使用してコードで生成されたオブジェクトにアクセスします。 次の例で、FusionServiceReferenceはサービス参照名です。 この例は、Webサービスを呼び出して、生成された参照オブジェクトを使用してルールを検索、作成および削除する方法を示します。
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);
}
}
}
}