Discussion:
byte[] and BizTalk
(too old to reply)
Dan Rosanova
2008-11-03 19:04:51 UTC
Permalink
Hello,
I've got an issue where a web service returns a message that's byte[]
within a response. This is a raw file (from SSRS). I want to use
BizTalk to save this file, but the only way I can think of is by
creating an XLANGMessage or something funny like that and I'm not sure
how to do it. Anyone have some advice?

Kind Regards,
-Dan
McGeeky
2008-11-04 08:28:03 UTC
Permalink
Hi Dan,

I am pretty sure you want to declare your message as an XMLDocument class;
it can handle unstructured data like bytes. Your FILE send port should then
use a pass through pipeline component.

McGeeky
Post by Dan Rosanova
Hello,
I've got an issue where a web service returns a message that's byte[]
within a response. This is a raw file (from SSRS). I want to use
BizTalk to save this file, but the only way I can think of is by
creating an XLANGMessage or something funny like that and I'm not sure
how to do it. Anyone have some advice?
Kind Regards,
-Dan
Dan Rosanova
2008-11-04 14:55:39 UTC
Permalink
Thank You,
Yea, XmlDocument is the way to go for the message, but you can't touch
it in the orchestration or it blows up. So what I've done is create a
pipeline component I call from the orchestration, which returns just
an IBaseMessage with the body part filled with the bytes. Now here is
my last issue (which I've solved, but don't like the solution to).
The raw text in the payload of the element I want to use (as the
source of the byte[]) is xs:base64Binary and it is longer than the
number of bytes I expect. If I just assign that, using xpath since it
is contained in an XML message, it is invalid data. If I instead use
the XmlSerializer to convert it into an instance of a class that
matches the schema the bytes are exactly as I want them. I would like
to avoid using the Serializer although I guess even just loading the
XmlDocument loads it all into memory anyway so I've already taken the
hit. Any suggestions? I'd really like to make this stream based.

Kind Regards,
-Dan
McGeeky
2008-11-04 22:47:44 UTC
Permalink
Hi Dan,

What are you trying to do with the message once you have received it from
Reporting Services? Its been a little while since I last did this so my
memory is not 100% fresh, but, I don't recall it being that tricky if all
you are looking to do is receive the report and write it out to a file.
There is no need to convert the message or touch it at all. Receive as an
XMLDocument then send it to a FILE send port using pass through pipeline
(out of the box one).

If you are still having issues with this then I'll fire up my old BizTalk
project and take a peek to see what I did.

Regards,

McGeeky
Post by Dan Rosanova
Thank You,
Yea, XmlDocument is the way to go for the message, but you can't touch
it in the orchestration or it blows up. So what I've done is create a
pipeline component I call from the orchestration, which returns just
an IBaseMessage with the body part filled with the bytes. Now here is
my last issue (which I've solved, but don't like the solution to).
The raw text in the payload of the element I want to use (as the
source of the byte[]) is xs:base64Binary and it is longer than the
number of bytes I expect. If I just assign that, using xpath since it
is contained in an XML message, it is invalid data. If I instead use
the XmlSerializer to convert it into an instance of a class that
matches the schema the bytes are exactly as I want them. I would like
to avoid using the Serializer although I guess even just loading the
XmlDocument loads it all into memory anyway so I've already taken the
hit. Any suggestions? I'd really like to make this stream based.
Kind Regards,
-Dan
Paul Somers[MVP]
2008-11-05 07:54:19 UTC
Permalink
Hi,

Your approach with the pipeline componet is correct, you can turn it into
anything you like, and thus remove the byte[] problem.

Try an xml streaming reader, try to avoid at all costs the xmldocument, as
it is a big hit, and it does load it all into memory, not a good idea ever,
not even inside an orchestration.

Paul.
Post by Dan Rosanova
Thank You,
Yea, XmlDocument is the way to go for the message, but you can't touch
it in the orchestration or it blows up. So what I've done is create a
pipeline component I call from the orchestration, which returns just
an IBaseMessage with the body part filled with the bytes. Now here is
my last issue (which I've solved, but don't like the solution to).
The raw text in the payload of the element I want to use (as the
source of the byte[]) is xs:base64Binary and it is longer than the
number of bytes I expect. If I just assign that, using xpath since it
is contained in an XML message, it is invalid data. If I instead use
the XmlSerializer to convert it into an instance of a class that
matches the schema the bytes are exactly as I want them. I would like
to avoid using the Serializer although I guess even just loading the
XmlDocument loads it all into memory anyway so I've already taken the
hit. Any suggestions? I'd really like to make this stream based.
Kind Regards,
-Dan
Saravana Kumar [MVP]
2008-11-05 12:02:40 UTC
Permalink
Ok, I saw this post yesterday and decided to explain bit more in detail.
Please visit the following link

http://blogs.digitaldeposit.net/saravana/post/2008/11/05/Dealing-with-web-services-returning-byte-in-BizTalk.aspx
--
Regards,
Saravana Kumar [MVP - BizTalk Server]
http://www.biztalk247.com/v1/
http://blogs.digitaldeposit.net/saravana/
Post by Paul Somers[MVP]
Hi,
Your approach with the pipeline componet is correct, you can turn it into
anything you like, and thus remove the byte[] problem.
Try an xml streaming reader, try to avoid at all costs the xmldocument, as
it is a big hit, and it does load it all into memory, not a good idea
ever, not even inside an orchestration.
Paul.
Post by Dan Rosanova
Thank You,
Yea, XmlDocument is the way to go for the message, but you can't touch
it in the orchestration or it blows up. So what I've done is create a
pipeline component I call from the orchestration, which returns just
an IBaseMessage with the body part filled with the bytes. Now here is
my last issue (which I've solved, but don't like the solution to).
The raw text in the payload of the element I want to use (as the
source of the byte[]) is xs:base64Binary and it is longer than the
number of bytes I expect. If I just assign that, using xpath since it
is contained in an XML message, it is invalid data. If I instead use
the XmlSerializer to convert it into an instance of a class that
matches the schema the bytes are exactly as I want them. I would like
to avoid using the Serializer although I guess even just loading the
XmlDocument loads it all into memory anyway so I've already taken the
hit. Any suggestions? I'd really like to make this stream based.
Kind Regards,
-Dan
Dan Rosanova
2008-11-05 15:35:34 UTC
Permalink
Hmm, I tried to post earlier this morning and I don't see my post
here.

System.Convert.FromBase64String(param1);

Is probably exactly what I was looking for. I don't need the
serializer here then. But Paul is right, loading this in an
XmlDocument will load it all into memory and I would really prefer to
stream it if I can. Anyone know a solution for that? Run a stream
from part of a message to the stream for a new message?

Also to be clear, my schema is like this

Response
Result
OtherNodes

I want the string (xs:base64Binary)

My resulting message has no schema, it is pure byte[], which is why I
need the pipeline. I use XmlDocument to represent it in my
orchestration and just don't do anything with it after I call the
pipeline. That wont result in it being completely loaded will it?


Kind Regards,
-Dan
Dan Rosanova
2008-11-05 14:55:46 UTC
Permalink
Thanks for the advice! My main issue is that the response document is
XML, but an element in it is a byte[] (xs:base64Binary). So it looks
like

Response
Result (xs:base64Binary)
SomeOtherNodes
MoreNodes

I want to put the Result element within this XML into a document.
What's really getting me now is that unless I serialize the response
message to a class using the XmlSerializer the bytes are encoded
incorrectly. Ultimately I'm trying to get from xs:base64Binary back
to whatever native windows encoded format this document was. It's an
excel document if that makes any difference. Is there some encoding I
could use with BinaryStream or something? I've tried them all and
they're all wrong for some reason. I really don't want to keep the
XmlSerializer in there due to the overhead Paul pointed out.

After some digging I saw that SSRS (which is what I'm connecting to)
does have sharepoint integration, so I was almost thinking of just
using that, but I really would like to keep BizTalk in the center and
avoid point to point integrations as much as possible.

Kind Regards,
-Dan
Saravana Kumar [MVP]
2008-11-05 15:49:39 UTC
Permalink
What about the solution explained for scenario 3 in the blog post.

I hope you can modify it little bit to suit your requirement
--
Regards,
Saravana Kumar [MVP - BizTalk Server]
http://www.biztalk247.com/v1/
http://blogs.digitaldeposit.net/saravana/
Post by Dan Rosanova
Thanks for the advice! My main issue is that the response document is
XML, but an element in it is a byte[] (xs:base64Binary). So it looks
like
Response
Result (xs:base64Binary)
SomeOtherNodes
MoreNodes
I want to put the Result element within this XML into a document.
What's really getting me now is that unless I serialize the response
message to a class using the XmlSerializer the bytes are encoded
incorrectly. Ultimately I'm trying to get from xs:base64Binary back
to whatever native windows encoded format this document was. It's an
excel document if that makes any difference. Is there some encoding I
could use with BinaryStream or something? I've tried them all and
they're all wrong for some reason. I really don't want to keep the
XmlSerializer in there due to the overhead Paul pointed out.
After some digging I saw that SSRS (which is what I'm connecting to)
does have sharepoint integration, so I was almost thinking of just
using that, but I really would like to keep BizTalk in the center and
avoid point to point integrations as much as possible.
Kind Regards,
-Dan
Dan Rosanova
2008-11-05 17:47:04 UTC
Permalink
Good point Saravana Kumar! I think something like that will work, my
main issue is that I think the call to GetBinary would require loading
the entire message into memory if I'm mistake. I usually do more
message only stuff so I'm wondering if I send an xpath of a message to
a method will it send the XML stream or the entire string of the
message? I suppose I'm going overboard on this considering that I
expect only a few of these messages a day and they'll certainly be
smaller than about 200KB. Not sure, coming from a high volume
background I know what I'm doing isn't the best way.

Kind Regards,
-Dan

Continue reading on narkive:
Loading...