receive binary file
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > BizTalk Server > BizTalk Server General > receive binary file




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    receive binary file  
Jeremy Chapman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-13-06 12:17 AM

I've got a file receive and send port, and am able to pass a binary file
from one port to the other in an orchestration using a message type of
xmldocument.  Now I want to do something with the binary data but because
the message type is xmldocument if I try to access the message biztalk tries
to load the document and barfs because it's expecting valid xml when the
data is actually binary.  How can I access the data?







[ Post a follow-up to this message ]



    Re: receive binary file  
BizTalkVirtuoso


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-13-06 12:17 AM

Jeremy,
Most likely you will need an external assembly to access the data.  You
will need to instantiate a class and call a method from the
orchestration passing the message as a parameter.  You should have
access to the data from the stream object.  Add a few try catch
statements to be sure.  Use a tool like DebugViewNT to monitor the
results.

Ben McFarlin
Microsoft BizTalk Server Consultant
www.biztalkvirtuoso.com






[ Post a follow-up to this message ]



    RE: receive binary file  
Matt Meleski


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-13-06 12:17 AM

From you orchestration you can call a .Net componet something similar to the
below:

public string GetRawMessage
(Microsoft.XLANGs.BaseTypes.XLANGMessage rawMessage)

{
System.IO.StreamReader reader = new
System.IO.StreamReader((System.IO.Stream)rawMessage[0].RetrieveAs(typeof
(System.IO.Stream)));
return reader.ReadToEnd();

}


"Jeremy Chapman" wrote:

> I've got a file receive and send port, and am able to pass a binary file
> from one port to the other in an orchestration using a message type of
> xmldocument.  Now I want to do something with the binary data but because
> the message type is xmldocument if I try to access the message biztalk tri
es
> to load the document and barfs because it's expecting valid xml when the
> data is actually binary.  How can I access the data?
>
>
>





[ Post a follow-up to this message ]



    Re: receive binary file  
BizTalkVirtuoso


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-13-06 06:19 PM

Exactly. Also use the BinaryReader object to get the byte array from
the Stream.

Ben McFarlin
Microsoft BizTalk Server Consultant
www.biztalkvirtuoso.com






[ Post a follow-up to this message ]



    Re: receive binary file  
Jeremy Chapman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:16 AM

OK, thanks.  Now I'm going to be passing this data to a web service, which
means I need to base64 encode the data, send it to the webservice and inside
the webservice I need to unencode it to use it.

What is the recommended way to do this?

Some issues I see:
BinaryReader has no size property, so how best to get the entire byte array
to base 64 encode it?
How do I know what encoding mechanism to use when converting to byte[]?
UTf-8, ascii, not sure.


"BizTalkVirtuoso" <ben.mcfarlin@biztalkvirtuoso.com> wrote in message
news:1150222074.760326.187530@g10g2000cwb.googlegroups.com...
> Exactly. Also use the BinaryReader object to get the byte array from
> the Stream.
>
> Ben McFarlin
> Microsoft BizTalk Server Consultant
> www.biztalkvirtuoso.com
>







[ Post a follow-up to this message ]



    Re: receive binary file  
BizTalkVirtuoso


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:16 AM

// Stream to Byte Array
BinaryReader reader = new BinaryReader(strm);
byte[] bytes = new byte[strm.Length];
reader.Read(bytes, 0, bytes.Length);

// Base64Encode
string s = Convert.ToBase64String(bytes);

// Base64Decode
byte[] bytes_out = Convert.FromBase64String(s);






[ Post a follow-up to this message ]



    Re: receive binary file  
Jeremy Chapman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:16 AM

BizTalk picks up a file from a directory, sends it contents to a web
service, and the web service is supposed to write the contents to a file.

I'm doing something wrong because the output file written by the webservice
isn't the same as the input file. I've created a method which gets the
binary data from an incomming message of type XmlDocument and Base64 encodes
it. The webservice decodes the base64 encode string and saves the file.  I'm
not sure what is going wrong.  when I debut it.  I know that the byte array
is the same length before encoding as after encoding, so characters must be
getting stripped out.  Any ideas?

public static string Encode64(Microsoft.XLANGs.BaseTypes.XLANGMessage
rawMessage)
{
System.IO.StreamReader pReader = new
System.IO.StreamReader((System.IO.Stream)rawMessage[0].RetrieveAs(typeof
(System.IO.Stream)));

return
System.Convert.ToBase64String(pReader.CurrentEncoding.GetBytes(pReader.ReadT
oEnd()));
}

[WebMethod]
public string SendBinary(string strFileName, string strData)
{
byte[] binData = System.Convert.FromBase64String(strData);

string strFileWrite =
System.IO.Path.Combine(this.Context.Request.PhysicalApplicationPath,
System.IO.Path.GetFileName(strFileName));

System.IO.FileStream pWrite = System.IO.File.OpenWrite(strFileWrite);
try
{
pWrite.Write(binData,0,binData.Length);
}
finally
{
pWrite.Flush();
pWrite.Close();
}
}

"BizTalkVirtuoso" <ben.mcfarlin@biztalkvirtuoso.com> wrote in message
news:1150222074.760326.187530@g10g2000cwb.googlegroups.com...
> Exactly. Also use the BinaryReader object to get the byte array from
> the Stream.
>
> Ben McFarlin
> Microsoft BizTalk Server Consultant
> www.biztalkvirtuoso.com
>







[ Post a follow-up to this message ]



    Re: receive binary file  
BizTalkVirtuoso


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:17 AM

Wait a minute. If you are trying to post the data to a web service then
you don't need an orchestration or an external assembly.  Just create
an HTTP Send Port that subscribes to the FILE Receive Port and route
the data as a passthru document.  Then create the web service method
that will capture the post data.

[WebMethod]
public string MyMethod()
{
Stream strm = Context.Request.InputStream;

try
{
BinaryReader reader = new BinaryReader(strm);
byte[] bytes = new byte[strm.Length];
reader.Read(bytes, 0, bytes.Length);

// do your work here

}
catch(Exception exc)
{
System.Diagnostics.EventLog.WriteEntry("BizTalk Server 2004",
exc.ToString(),  System.Diagnostics.EventLogEntryType.Error);
throw exc;
}
}
return "For BizTalk Server 2004 Consumption Only";
}






[ Post a follow-up to this message ]



    Re: receive binary file  
Jeremy Chapman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:17 AM

Wish I could do it without the orchestration.  I need to parse the file
name, and pass it to the web service.

"BizTalkVirtuoso" <ben.mcfarlin@biztalkvirtuoso.com> wrote in message
news:1150226979.807235.291900@f6g2000cwb.googlegroups.com...
> Wait a minute. If you are trying to post the data to a web service then
> you don't need an orchestration or an external assembly.  Just create
> an HTTP Send Port that subscribes to the FILE Receive Port and route
> the data as a passthru document.  Then create the web service method
> that will capture the post data.
>
> [WebMethod]
> public string MyMethod()
> {
>    Stream strm = Context.Request.InputStream;
>
>    try
>    {
>      BinaryReader reader = new BinaryReader(strm);
>      byte[] bytes = new byte[strm.Length];
>      reader.Read(bytes, 0, bytes.Length);
>
>      // do your work here
>
>    }
>    catch(Exception exc)
>    {
>      System.Diagnostics.EventLog.WriteEntry("BizTalk Server 2004",
> exc.ToString(),  System.Diagnostics.EventLogEntryType.Error);
>      throw exc;
>    }
>  }
>  return "For BizTalk Server 2004 Consumption Only";
> }
>







[ Post a follow-up to this message ]



    Re: receive binary file  
BizTalkVirtuoso


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:17 AM

FTP Adapter?






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:11 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register