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.

http://code.msdn.microsoft.com/Send-Soap-with-Attachments-3784e5f6

Shankar

Visits: 799

0 0 vote
Article Rating
Subscribe
Notify of
guest
15 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ilya

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

Thank you,
Ilya

shankarsbiztalk

Hey
Sorry, I have now uploaded the source code in http://code.msdn.microsoft.com/Send-Soap-with-Attachments-3784e5f6.

Let me know if you get into trouble.

Shankar

Michel Pauwels

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

shankarsbiztalk

Hey Michel,
Sorry, I have now uploaded the source code in http://code.msdn.microsoft.com/Send-Soap-with-Attachments-3784e5f6.

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. 🙂

Shankar

Binh

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
Host: http://www.example2.com
SOAPAction: “ebXML”
Content-type: multipart/related; boundary=”BoundarY”; type=”text/xml”;
start=””
This is an ebXML HTTP POST Example
–BoundarY
Content-ID:
Content-Type: text/xml

O01
XyZ company
from@example.com

O03
IZStock
to1@example2.com

Attach Description

–BoundarY
Content-ID:
Content-Type: text/xml

Title of cocument

VV38rRdzvVbXop4SwZQgY56VZTBLmltDDwGy0SQ/Rb7BzgVlNTEyc9CSpA0w/hOxMat+4n
5/QIF9Gl2Bq/ZhGg+D5ZRB1oRtGMosNlh8uMFkIU4Yqne8uJ/nSXQzC7vZL+I/OpIjQ1dWz2
WAtbxN/N4eTfy8d2+zgph5fV9GndzfvB2K/BfjX2fXxEr0rnj5qE0mHWV3xKnPe9sU+4W4kb
90U9rfc7JyojZtdEJR7KPgn7Tx4lKsSFE6YgL8SPI72fqX/0dmvlGUMU0qcFqd/xidb5aXut
fVrg+BX0iwP9E4/4igwl3bjn/DPjzfkY4zsN5WvXtzTI/W2VH+9fwD7zIaLFZG5na8PeHGWv
tafBhz7H3tej4OH08r86tPM0u9sxhOgz7PehHrFSPhWPEPV1Et2Jfk0hxf44HMV5F7H/jylK
fF06cCrxJKn8tgpaOVrQ+ofLOeQ024+sb3nfXGjOHo12aRfSUP7kr1Ge1s92cmN7tPlB3rsw
4exNxHwRZi3nwHK76zmEMq/Je561eR9GUX4b+yH8EFoXJtJ1r48y6X7KIR/IpgPiaITYR+Mo
lw55Od1HY2kjjkbhaAJtdLA0HEyg97zp1N2/+WgA5rF7aSD1p/EU4+iHMjKR1wjyUBadUHPI
pvdRpg8j+HURO+EdjX0Wjhq8XI9ROOrt4DMm0Wh6w5sranc/PYQSYxwnvfmIz6E/e0uw7ydq
eRnXFdAv1Xg2bfIWUyGOSvD3JuWrtR0r0meJNmxyFFNfHHG8jp7AkU/U3EfluOYsKef5cLfg

–BoundarY–

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

Thanks.

shankarsbiztalk

Hello,

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

http://stackoverflow.com/questions/4437660/how-do-i-modify-wcf-to-process-messages-in-a-different-non-soap-format/4439003#4439003

There is also a ready made availlable in github.

https://github.com/miked30/EbXmlSample

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

Shankar

Binh

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.

shaik

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 values.to 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
encoder:binery

–boundery

–boundary–

Hope you understand this.

request nyour assitance on proceeding.

Awaiting for your sooner response

shaik

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

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

–uuid:Same GUID
Content-Id:XXXX@example.jaxws.sun.com>
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
——-TestFile—-
Attachment COntent
–uuid:Same GUID–

ramesh

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.

shankarsbiztalk

I have given a rough idea for implementation. Pls have a look.
https://shankarsbiztalk.wordpress.com/2015/08/03/sending-soap-with-attachments-swa-using-biztalk-part-2/

Let me know if you need any help

Alex

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

Alex

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.

shankarsbiztalk

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

shankarsbiztalk

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))
{
cf.Open();
var channel = cf.CreateChannel();

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

using (var scope = new OperationContextScope((IContextChannel)channel))
{
OperationContext.Current.OutgoingMessageProperties[SwaEncoderConstants.AttachmentProperty] =
cardDetails.Attachment.ToSimpleXmlUTF8();
ret = channel.cardApplication(request).cardApplicationResponse;
}
try
{
cf.Close();
}
catch
{
cf.Abort();
throw;
}
}

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

Regards
Shankar

15
0
Would love your thoughts, please comment.x
()
x