Hello
Ever needed to send a message to BizTalk using c# native code?
if your answer is yes, you are reading the right post.
I will demonstrate 2 ways of submitting a message to BizTalk, one using a netPipe receive location and the other is using the ESB.OnRamp.Itinerary.WCF receive location. (Vishal Mody has a very good post on the netPipe bindings at his blog)
as the code below shows, it is all about the bindings…
The code
- Add reference to the following assemblies:
- System.ServiceModel
- System.Runtime.Serialization
- For both scenarios (netPipe and ESB on ramp) we create the interface:
//Using statements
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;
using System.IO;
[ServiceContract()]
private interface IBizTalkSubmission
{
[OperationContract(Action="*", ReplyAction="*")]
void Submit(System.ServiceModel.Channels.Message msg);
}
- NetPipe receive location
public void SubmitDocument(string Xml)
{
//Create the Message
System.ServiceModel.Channels.Message msg = System.ServiceModel.Channels.Message.CreateMessage(MessageVersion.Default, “*”, XmlTextReader.Create(new StringReader(Xml)));
//Set required properties
string uriLocationEsbOnRamp = “net.pipe://BizTalk/someName”;
NetNamedPipeBinding b = new NetNamedPipeBinding();
//Handle security if needed
b.Security.Mode = NetNamedPipeSecurityMode.None;
EndpointAddress epa = new EndpointAddress(uriLocationEsbOnRamp);
IBizTalkSubmission proxy = ChannelFactory.CreateChannel(b, epa);
//submit the message
proxy.Submit(msg);
}
- ESB.OnRamp.Itinerary.WCF receive location
public void SubmitDocumentUsingESB(string Xml)
{
Message msg = System.ServiceModel.Channels.Message.CreateMessage(MessageVersion.Default, “*”,
XmlTextReader.Create(new StringReader(Xml)));
string uriLocationEsbOnRamp = “http://localhost/ESB.ItineraryServices.WCF/ProcessItinerary.svc“;
WSHttpBinding b = new WSHttpBinding();
EndpointAddress epa = new EndpointAddress(uriLocationEsbOnRamp);
IBizTalkSubmission proxy = ChannelFactory<IBizTalkSubmission>.CreateChannel(b, epa);
proxy.Submit(msg);
}
BTS admin console settings
NetPipe receive location
make sure that the URI you have in the code ( string uriLocationEsbOnRamp = “net.pipe://BizTalk/someName” in our example) is the same in the URI section for the transport properties.(see image below)
ESB.OnRamp.Itinerary.WCF receive location
No need to modify any settings.
if you get an error regarding the body of the incoming message, look at the “Messages” tab for this receive location. in this example the “Body” element was in the “soap:Body” element so the settings is as shown below.


