Hi there,
Today we will be doing a quick little test to send a XML message to BizTalk with few lines of code. I had a scenario in my solution in which I had a WCF LOB Outbound Adapter which was doing some work and later the same code had to submit message back to BizTalk. First solution I thought of was writing the message to a File Location and than a BizTalk Receive Location picks it up from there and processes it. But then came up with a different solution of using WCF netPipe and submitting it directly to BizTalk.
Anyways, I created a small Console App which just take a XML from a file location (which in my code was the WCF Outbound Adapter forming this XML message) and then send to BizTalk and there is a Send Port putting this message out to another file location. Below are the steps.
· Create a new Console Application.
· Add reference to the following assemblies
o System.Runtime.Serialization
o Sytem.ServiceModel
· Below is the piece of code which does the work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;
using System.IO;
namespace TestConsole
{
public class SendBizTalk
{
[ServiceContract()]
private interface IBizTalkSubmission
{
[OperationContract(Action = "*", ReplyAction = "*")]
void Submit(Message msg);
}
static void Main(string[] args)
{
XmlTextReader xmlrdr = new XmlTextReader(@"C:\Test\In\Test.xml");
Message msg = Message.CreateMessage(MessageVersion.Default, "*", xmlrdr);
string uriLocationEsbOnRamp = "net.pipe://localhost/SendBizTalk";
NetNamedPipeBinding b = new NetNamedPipeBinding();
b.Security.Mode = NetNamedPipeSecurityMode.None;
EndpointAddress epa = new EndpointAddress(uriLocationEsbOnRamp);
IBizTalkSubmission proxy = ChannelFactory<IBizTalkSubmission>.CreateChannel(b, epa);
proxy.Submit(msg);
}
}
}
· Build the solution à Successful. Nice
· Next thing is to configure BizTalk Receive and Send port.
· Open BizTalk Administration Console and select the Application where you want the Receive and Send Port.
· Next create a new Receive Port name TestRcvPort and a Receive Location for it name TestRcvLocation.
· For the Receive Location select the Type as “WCF-NetNamePipe” and in than click Configure.
· For the Address URI copy the URI which you specified in the Code. There is a very cool thing about this, you can fetch this URI from SSO Config also. I will show this in my next blog. But for now let hard code it. "net.pipe://localhost/SendBizTalk".
· Nothing to be changed in the Binding Tab. Next is the Security Tab, by default it would be Transport, so change it to None.
IMPORTANT: If you have Security set to None, then you code should also reflect the same security configuration. Like in the code above you can see the following line which sets the security as none.
NetNamedPipeBinding b = new NetNamedPipeBinding();
b.Security.Mode = NetNamedPipeSecurityMode.None;
· Nothing to be changed in the Messages tab. Select the Receive Pipeline you want to use. For this test App I have PassThruReceive. You can use your own custom Pipeline or use ESB pipelines and then complete ESB stuff i.e. XMLDissembler, BRE, Maps etc etc but for now lets keep it simple.
· Next to create a Send Port named “TestSndPort”. Select the Type as File and Configure it to point to some file location.
· In the Filer tab select the BTS.ReceivePortName == TestRcvPort
· Start/Enable the Receive Location and Send Port. Put a test message you want to test at C:\Test\In\Test.xml location. Run the Console app and check the output for the Send Port. Success….!!!!!
· Total time of creating the app with the same piece of code and using any xml à around 5 mins.
· Time for entire code to run with simple BizTalk artifacts à Fraction of Second.
Thanks,
Vishal