This is a continuation to my previous article. Please have a look if you hadn’t seen it.

Sending Soap with Attachments (SwA) using BizTalk

Below are the steps that we have to follow for this exercise.

1. Create a custom message encoder which can send XML as an attachment in the SOAP envelope message.

2. Create a WCF service which can send the SOAP message with attachment.

3. Create the BizTalk application which can consume the custom WCF service.

Steps are easy isn’t. In this post we will only cover Step 1.

As I have told in the previous post, this custom encoder has been developed by Austrin interoperablity council and they have published the code in Codeplex. I have taken this code and removed some hard coded stuff and placed it in configurable properties.

I have uploaded the full source code below.


Visits: 799

0 0 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments

Hi Shankar,
Thank you for great job.
The link to source code doesn’t work.
Can you post another one?

Thank you,


Sorry, I have now uploaded the source code in

Let me know if you get into trouble.


Michel Pauwels

Sadly enough the source download link seems to be broken.
Any chance that you could reupload it?


Hey Michel,
Sorry, I have now uploaded the source code in

Let me know if you get into trouble.

And BTW, in 2006 when I was working in India, Codit was our client. I worked with Stijn and Sam during that time. 🙂



Hi, i want to write a webservice in C# ASP.NET that have a WebMethod accept soap message with Attachments Message and Some input parametter are put in the header. The income Soap Message Like a ebXML message. The soap message must be multipart/related; and boundary.

My task are write an application using C# to exchange the message between systems.
The application have two functions:
1. First function is receive message: It accept message from another system, the message from other system is like ebXML it is multipart/related, boundary. This function pare message and get data to save to database.

2. The second is Send Message: Other systems maybe use Sun or Microsoft technology… and I don’t know what it is, it just know that it’s allow others system send message to them by compose a message like ebXML message as receive message function above.

But i don’t know how to implement this. I google and found your issue, i wonder if i can write a WCF to receive message with content type is multipart/related; and boundary and some parameter is put in the Soap Header.

I know that WCF support MessageContract so we can set member of Message to Header or Body, but I cannot specified the namespace like the message as required

Below is an example of request soap message that the customer require me to write system to exchange it.

POST /servlet/ebXMLhandler HTTP/1.1
SOAPAction: “ebXML”
Content-type: multipart/related; boundary=”BoundarY”; type=”text/xml”;
This is an ebXML HTTP POST Example
Content-Type: text/xml

XyZ company


Attach Description

Content-Type: text/xml

Title of cocument



I don’t know how to implement this using ASP.NET, do you have an idea?
Could you help me?




Please see the below link to implement a WCF service that can accept ebXML format both in send and receive methods.

There is also a ready made availlable in github.

However as in your case, you need will receive the message with multipart/related boundaries, you will have to use a custom message encoder. Please go through the custom message encoder which in included in my code.

Let me know your comments



HI, i intend to use soap header to append some header like ebXML message, and the boundary is an attactment.

So i Create a class that inheritance from SoapHeader so element of this class will be in the Soap header, but i meet a problem is the namespace of Header element does not have prefix, but in the edXML header have prefix edXML. I don’t know how to add prefix namespace.

Because my system must provide a method that allow other system send the message to, and the message of other system is an edXML.


Great Work..I have implemented this in my solution.
But I am getting error in MIME parser. Http content type is missing start tag and throws exception.
When I see soap response, its not having start , only boundry and type are available.
I tried to comment start in the code and also tried to give some static start even, but no luck. during debugging. error non-negative,param count. Failing at

string TransferEncoding = ParserEncoding.GetString(binaryContent, TransferEncodingIdx + TransferEncodingKeyBytes.Length, ContentIdIdx – (TransferEncodingIdx + TransferEncodingKeyBytes.Length)).TrimStart().TrimEnd();

ContentIdIdx lengths is less….

Only one attachment will come in soap response and its txt file.
name of the attachment will be available in one xml tag of soap body response

Apologize as I couldn’t upload exact soap response. However just briefing the structure
multipart/ , contenty type “text/xml” boundry :”uuid: ”

contenttype : application/ocstream
content id : same as in the soap body



Hope you understand this.

request nyour assitance on proceeding.

Awaiting for your sooner response


Also noticed that the method(DeserializeMimeContent) is not adding soap response . I have seen only attachment getting added to MIME and not SOAP Response.

Content-Type: text/xml; charset=utf-8
?xml version=’1.0′ encoding=’UTF-8′?>

–uuid:Same GUID>
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Attachment COntent
–uuid:Same GUID–


Hi Sankar,

Could you please tell us how to use this message encoder in the WCF service,which means
your point 2 Create a WCF service which can send the SOAP message with attachment.


I have given a rough idea for implementation. Pls have a look.

Let me know if you need any help


Could you provide an example that use your SWA project please ?


I have to send xml request with attachement but I can’t find anything helpful on the web. I’m a beginer with these attachements and I don’t understand how to use your project.

Thank you for your help.


Are you going to use BizTalk to send SOAP with attachments or just WCF to send it?


In any case, let me first give you an idea of how to use it in WCF.

When I doing this development, I had to consume a JAVA service. When I added web reference to the WSDL, the proxy types generated were not exactly as expected by the JAVA service. So the first thing, that I had to do hand create the proxy types using the WSDL description.

After that, we will implement the service as below

public CardApplicationResponseWrapper cardApplication(CardApplicationRequestWrapper request)
string fisCardApplicationEndPoint = System.Configuration.ConfigurationManager.AppSettings["CardApplicationSvcURL"].ToString();

CardApplicationResponse ret = null;

using (var cf = new ChannelFactory(CardApplicationEndPoint))
var channel = cf.CreateChannel();

CardDetails cardDetails = (CardDetails)request.cardApplication.cardDetails;

using (var scope = new OperationContextScope((IContextChannel)channel))
OperationContext.Current.OutgoingMessageProperties[SwaEncoderConstants.AttachmentProperty] =
ret = channel.cardApplication(request).cardApplicationResponse;

CardApplicationResponseWrapper response = new CardApplicationResponseWrapper();
response.cardApplicationResponse = ret;

return response;

I will try to create a sample project for the service implementation and will attach it to the post soon


Would love your thoughts, please comment.x