Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Biztalk 2004: How to pass database facts from C# code?
- This topic has 1 reply, 1 voice, and was last updated 8 years, 3 months ago by
community-content.
-
AuthorPosts
-
-
June 21, 2006 at 8:20 PM #13892
[code:1:dc8a31d13c]
HiTools: C#, .NET 1.1 and Biztalk 2004
I want to execute a policy rule which gets fired based on some input xml and database facts. I am able to pass the input xml facts but how to I pass the database facts information before executing policy. Basically, by passing \"Role\" information, I want to get \"Salary\" values which are stored in a database table.
Following is the code snippet:
————————————————————–
Input XML:<ns0:EmpInfo xmlns:ns0=\"http://EmployeeInfo.EmpInfo\">
<Emp>
<Salary></Salary>
<Role>Manager</Role>
</Emp>
<Emp>
<Salary></Salary>
<Role>CIO</Role>
</Emp>
</ns0:EmpInfo>————————————————————–
—————————-
public string Execute(string sRequestXML, out string sResponseXML, out string sErrorMsg)
{
sResponseXML = string.Empty;
sErrorMsg = string.Empty;
DebugTrackingInterceptor dti = new DebugTrackingInterceptor(@\"C:\\Biztalk\\projects\\EmployeeInfo\\XSDs\\jit.txt\");//create an instance of the XML object
XmlDocument xd1 = new XmlDocument();
xd1.Load(@\"C:\\Biztalk\\projects\\EmployeeInfo\\XSDs\\Copy of EmpInfo_output.xml\");TypedXmlDocument doc1 = new TypedXmlDocument(\"EmpInfo\",xd1);
// create the array of short-term facts
object[] shortTermFacts = new object[1];
shortTermFacts[0] = doc1;Policy policy = null;
// now execute to see what happens
try
{//Console.WriteLine(\"Grabbing the policy …\");
policy = new Policy(\"EmpInfo\");
policy.Execute(shortTermFacts, dti);FileInfo finfo = new FileInfo(@\"C:\\Biztalk\\projects\\EmployeeInfo\\XSDs\\ProcessedRFP.xml\");
StreamWriter writer = finfo.CreateText();
writer.Write(doc1.Document.OuterXml);
writer.Close();}
catch (Exception ex)
{
FileInfo finfoError = new FileInfo(@\"C:\\Biztalk\\projects\\EmployeeInfo\\XSDs\\Error.xml\");
StreamWriter writerError = finfoError.CreateText();
writerError.Write(ex.Message);
writerError.Close();
}dti.CloseTraceFile ();
policy = null;
return \"PASS\";}
[/code:1:dc8a31d13c]
-
June 21, 2006 at 9:45 PM #13891
Create a C# or VB .Net script to extract the fact (s) from the database. Push this mini app up to the GAC. You can then call this script via a scripting functiod in a map and update the salary field. The map can be called from the orchestration (make sure to reference the mini app for the function).
-OR-
You can call the DB function written above directly in the orchestration (must be in an atomic scope shape) and set result of call to a variable and then Xpath in the result of the call in a construct statement in another expression shape.
Hope this helps.
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.