how to send a file using webservices?
-
what is the best way to send an arbitrary file through webservices? (I think transforming it to an array of bytes is not a good idea...)
I would say array of bytes is good enough, actually file is exactly that: array of bytes. You don't have to transform anything, just load your file from FileStream into byte array. check this article, maybe it helps you: http://www.codeproject.com/vb/net/wsfileserver.asp Pilo
-
I would say array of bytes is good enough, actually file is exactly that: array of bytes. You don't have to transform anything, just load your file from FileStream into byte array. check this article, maybe it helps you: http://www.codeproject.com/vb/net/wsfileserver.asp Pilo
Thank you for the answer, when I said "transform" I meant "load" but when passing through the webservices an array of bytes will be transformed to some xml-data, something like this: (array)(byte)1(/byte)(byte)2(/byte)(/array) This data contains a lot of unnecessary information (repeated "byte" nodes). Are there any techinques to send the file in more compact format that needs less memory size?
-
what is the best way to send an arbitrary file through webservices? (I think transforming it to an array of bytes is not a good idea...)
Strictly speaking, you can't send a file through webservices, you can only send the data in the file. If you can't assume anything about the content of the file, a byte array is the only way that you can represent the data in the file. You can then convert the bytes to anything you like, for example a Base64 string, but there is no way around the byte array.
--- single minded; short sighted; long gone;
-
Strictly speaking, you can't send a file through webservices, you can only send the data in the file. If you can't assume anything about the content of the file, a byte array is the only way that you can represent the data in the file. You can then convert the bytes to anything you like, for example a Base64 string, but there is no way around the byte array.
--- single minded; short sighted; long gone;
I understand that I can send only the data in the file. The question is how to represent this data for transfering through webservices? I want the memory size of my file data to be as small as it can be. For example, if I have an array of bytes, data that passes through webservices should look like this: (array)(byte)1(/byte)(byte)2(/byte)(/array). And it's not very good, because "byte" xml-nodes are repeated too often. And the string representation causes some problems with encodings.
-
Thank you for the answer, when I said "transform" I meant "load" but when passing through the webservices an array of bytes will be transformed to some xml-data, something like this: (array)(byte)1(/byte)(byte)2(/byte)(/array) This data contains a lot of unnecessary information (repeated "byte" nodes). Are there any techinques to send the file in more compact format that needs less memory size?
I think WCF is the solution for you. WCF supports Large Message Transfer. If you want to use Http protocol, you need to use wsHttpBinding (design to supports SOAP 1.2 standard; amsx web service is SOAP 1.1 standard). To support Large Message Transfer, you can set messageEncoding to MTOM (MTOM stands for Message Transmission Optimization Mechanism). You also need to adjust the maxReceiveMessageSize and maxReceiveMessageSize of the binding because the default is not very large.
petersgyoung
-
I understand that I can send only the data in the file. The question is how to represent this data for transfering through webservices? I want the memory size of my file data to be as small as it can be. For example, if I have an array of bytes, data that passes through webservices should look like this: (array)(byte)1(/byte)(byte)2(/byte)(/array). And it's not very good, because "byte" xml-nodes are repeated too often. And the string representation causes some problems with encodings.
You can turn it into a Base64 string using the
Convert.ToBase64String
method, and convert it back to a byte array using theConvert.FromBase64String
. The Base64 encoding stores 6 bits in each character, which gives you an overhead of only 33%.--- single minded; short sighted; long gone;
-
I think WCF is the solution for you. WCF supports Large Message Transfer. If you want to use Http protocol, you need to use wsHttpBinding (design to supports SOAP 1.2 standard; amsx web service is SOAP 1.1 standard). To support Large Message Transfer, you can set messageEncoding to MTOM (MTOM stands for Message Transmission Optimization Mechanism). You also need to adjust the maxReceiveMessageSize and maxReceiveMessageSize of the binding because the default is not very large.
petersgyoung
-
what is the best way to send an arbitrary file through webservices? (I think transforming it to an array of bytes is not a good idea...)
-
If you want to stick to older technology, you can try WSE (Web Service Enhancement). If I remember correctly, WSE is an add-in which makes SOAP with Attachments (SwA) and Direct Internet Message Encapsulation(DIME) possible on older framework, e.g. .Net 1.1. I, however, do not recommend you to learn phasing out technology. SwA and DIME are now replaced by MTOM.
petersgyoung
-
If you want to stick to older technology, you can try WSE (Web Service Enhancement). If I remember correctly, WSE is an add-in which makes SOAP with Attachments (SwA) and Direct Internet Message Encapsulation(DIME) possible on older framework, e.g. .Net 1.1. I, however, do not recommend you to learn phasing out technology. SwA and DIME are now replaced by MTOM.
petersgyoung
-
You can turn it into a Base64 string using the
Convert.ToBase64String
method, and convert it back to a byte array using theConvert.FromBase64String
. The Base64 encoding stores 6 bits in each character, which gives you an overhead of only 33%.--- single minded; short sighted; long gone;
-