Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to send a file using webservices?

how to send a file using webservices?

Scheduled Pinned Locked Moved ASP.NET
questiondata-structurestutorial
13 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S steve_a_p

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

    G Offline
    G Offline
    Guffa
    wrote on last edited by
    #4

    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;

    S 1 Reply Last reply
    0
    • G Guffa

      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;

      S Offline
      S Offline
      steve_a_p
      wrote on last edited by
      #5

      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.

      G 1 Reply Last reply
      0
      • S steve_a_p

        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?

        P Offline
        P Offline
        petersgyoung
        wrote on last edited by
        #6

        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

        S 1 Reply Last reply
        0
        • S steve_a_p

          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.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #7

          You can turn it into a Base64 string using the Convert.ToBase64String method, and convert it back to a byte array using the Convert.FromBase64String. The Base64 encoding stores 6 bits in each character, which gives you an overhead of only 33%.

          --- single minded; short sighted; long gone;

          S 1 Reply Last reply
          0
          • P petersgyoung

            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

            S Offline
            S Offline
            steve_a_p
            wrote on last edited by
            #8

            But WCF is a part of .NET 3.0. Are there any methods to do this using .NET 2.0?

            P 1 Reply Last reply
            0
            • S steve_a_p

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

              S Offline
              S Offline
              steve_a_p
              wrote on last edited by
              #9

              I don't know, may be there is some special stream for sending file data from client to server at once, isn't there? -- modified at 5:09 Friday 31st August, 2007

              1 Reply Last reply
              0
              • S steve_a_p

                But WCF is a part of .NET 3.0. Are there any methods to do this using .NET 2.0?

                P Offline
                P Offline
                petersgyoung
                wrote on last edited by
                #10

                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

                S 1 Reply Last reply
                0
                • P 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

                  S Offline
                  S Offline
                  steve_a_p
                  wrote on last edited by
                  #11

                  Ok, thank you, I'll think about this

                  1 Reply Last reply
                  0
                  • G Guffa

                    You can turn it into a Base64 string using the Convert.ToBase64String method, and convert it back to a byte array using the Convert.FromBase64String. The Base64 encoding stores 6 bits in each character, which gives you an overhead of only 33%.

                    --- single minded; short sighted; long gone;

                    S Offline
                    S Offline
                    steve_a_p
                    wrote on last edited by
                    #12

                    But 2 bits will be lost, won't they? (I am not strong in encodings...)

                    G 1 Reply Last reply
                    0
                    • S steve_a_p

                      But 2 bits will be lost, won't they? (I am not strong in encodings...)

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #13

                      steve_a_p wrote:

                      But 2 bits will be lost, won't they?

                      Of course not, that would be pointless. All the bits are distributed across characters. Three bytes (3*8 bits) are stored in four characters (4*6 bits).

                      --- single minded; short sighted; long gone;

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups