Link to home
Start Free TrialLog in
Avatar of jwblair2009
jwblair2009

asked on

Can not use memory stream from my web service

I have created a web service returning a memory stream. The client interfaces to the web service via a service reference. When I try to use the stream in my client from the web service, I get the following error:

Cannot convert type 'interchangeCalculations.iccServiceReference.MemoryStream' to 'System.IO.MemoryStream'

This makes no sense to me since a memory stream is a just a memory stream. This worked in my test app when I was creating and processing the stream in the same application. Now that I am connecting the client to a web service to get the stream, it fails. How do I get around this? The below cast for the memory stream also fails.

MemoryStream streamBinary = (MemoryStream)myIccWebService.getEftTranDataBinarySerialized(startTime, endTime);
sicInfoDataSetNotTyped = binaryDeSerialize(streamBinary);

Open in new window

Avatar of jwblair2009
jwblair2009

ASKER

A better/similar/Another description. This question was found on another website and was not answered.

I am using an XMLSerializer to create an xml object of a
class in a web application. I am then using an XMLWriter
to place this into a memory stream. No problems so far.

I have a web service that is to receive a
System.IO.MemoryStream object and then deserialize it to
retrieve the require information.

When I try to make the call to the WebMethod from my web
application the IDE is showing that it is not expecting a
System.IO.MemoryStream object, but is expecting an object
of type <WebService>.<Service>.MemoryStream i.e.
WebApplication.WebService.SystemMemoryStream.

If I just pass my memory stream object I get the compile
error: Cannot Convert from 'System.IO.MemoryStream'
to 'WebApplication.WebService.MemoryStream'.

Any ideas on why this isn't working? Or is there a better
way to do this???
The only thing that I see that even comes close to solving this is to convert the stream to a byte array. Got any other better ideas?
ASKER CERTIFIED SOLUTION
Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there any documentation on MSDN to support this?
Ok, now that I have created a byte array, I am now getting this error.

System.Runtime.Serialization.SerializationException: Unable to find assembly 'interchangeCalculationsWebService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at interchangeCalculations.interchangeCalculationsApplication.binaryDeSerialize(MemoryStream stream) in C:\Projects\ICC\version 1.2.1\source code\interchangeCalculations.root\interchangeCalculations\interchangeCalculations\interchangeCalculationsApplication.cs:line 1960
      
Sample of serialization and deserialization is given in vb please change it to C#.

But you error says that, it couldn't find assembly "interchangeCalculationsWebService".  Provide proper path or copy that to the required place.
Public Class Utils
    Public Shared Function Serialize(ByVal Obj As Object) As Byte()
        Dim bf As New BinaryFormatter
        Dim mem As New MemoryStream
        Try
            bf.Serialize(mem, Obj)
        Catch ex As Exception
            Throw ex
        End Try
        Return mem.ToArray
    End Function
 
    Public Shared Function Deserialize(ByVal bytes() As Byte) As Object
        Dim bf As New BinaryFormatter
        Dim mem As New MemoryStream(bytes)
        Dim obj As Object
        Try
            obj = bf.Deserialize(mem)
        Catch ex As Exception
            Throw ex
        End Try
        Return obj
    End Function
End Class

Open in new window

Thanks, but I solved the problem on my own. The problem was that I created a class to determine how to serialize a dataset. The class was in the web service but not in the client. Thus I created a DLL for the class and included it both in the web service and the client. Then the same assembly was found in both places, and now it works.

Thanks to everyone that participated.
Memory streams in a web service are not supported, but not alternative solution was provided.
apeter said to use a byte array, but did not provide to turn that dataset to a byte array.
apeter, you jogged my memory to point me to the correct solution, thanks for help and sorry to everyone else for the multiple postings.