Does the type conflict with ITSELF just because it is included as a web method return type in an ASP.NET web service?

I have an annoying problem, I am creating an asp.net webservice; this service should expose the functionality of an existing library, this service allows users to upload files to our server by calling the UploadFile method on the service. Here's the signature of the UploadFile method

public bool UploadFile(string bucketName, string desiredFileName, System.IO.Stream fileData)

      


Now when I try to call this method and pass it a System.IO.Stream object referencing the file to be loaded, I get a compile-time error indicating the passed type (System.IO.Stream) is not an expected type (Mynamespace.ServiceReference .Stream). I tried to explicitly pass my stream to the type (Mynamespace.ServiceReference.Stream), but the compiler didn't give me that either, although they are of the same type! weired!

0


a source to share


2 answers


The problem is to generate a WSDL that the Stream will try to serialize, which it cannot do.

The original idea of ​​the byte [] is the correct way to do it.



You don't need to worry about the Base64 conversion because the ASP.NET runtime will do it for you already.

+2


a source


Here's the Solution.

Instead of having byte [] in the argument for file data, use the base64 string representation by byte [].

from the client that is consuming your webservice, have it convert the [] bytes to base64 string and then pass that to your webservice call. At the server end, you have to get the base64 string of the byte array and convert it back to byte [].

Here are links to conversion methods in the .NET Framework.



Bytes [] to Base64 - for use in webservice clients

link text: http://msdn.microsoft.com/en-us/library/dhx0d524.aspx

Base64 to Byte [] - For use in webservice server

link text: http://msdn.microsoft.com/en-us/library/system.convert.frombase64string.aspx

0


a source







All Articles