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.i ccServiceR eference.M emoryStrea m' 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.
Cannot convert type 'interchangeCalculations.i
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);
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there any documentation on MSDN to support this?
ASKER
Ok, now that I have created a byte array, I am now getting this error.
System.Runtime.Serializati on.Seriali zationExce ption: Unable to find assembly 'interchangeCalculationsWe bService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Runtime.Serializati on.Formatt ers.Binary .BinaryAss emblyInfo. GetAssembl y()
at System.Runtime.Serializati on.Formatt ers.Binary .ObjectRea der.GetTyp e(BinaryAs semblyInfo assemblyInfo, String name)
at System.Runtime.Serializati on.Formatt ers.Binary .ObjectMap ..ctor(Str ing objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
at System.Runtime.Serializati on.Formatt ers.Binary .__BinaryP arser.Read ObjectWith MapTyped(B inaryObjec tWithMapTy ped record)
at System.Runtime.Serializati on.Formatt ers.Binary .__BinaryP arser.Run( )
at System.Runtime.Serializati on.Formatt ers.Binary .ObjectRea der.Deseri alize(Head erHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter.Des erialize(S tream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serializati on.Formatt ers.Binary .BinaryFor matter.Des erialize(S tream serializationStream)
at interchangeCalculations.in terchangeC alculation sApplicati on.binaryD eSerialize (MemoryStr eam stream) in C:\Projects\ICC\version 1.2.1\source code\interchangeCalculatio ns.root\in terchangeC alculation s\intercha ngeCalcula tions\inte rchangeCal culationsA pplication .cs:line 1960
System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at System.Runtime.Serializati
at interchangeCalculations.in
Sample of serialization and deserialization is given in vb please change it to C#.
But you error says that, it couldn't find assembly "interchangeCalculationsWe bService". Provide proper path or copy that to the required place.
But you error says that, it couldn't find assembly "interchangeCalculationsWe
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
ASKER
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.
Thanks to everyone that participated.
ASKER
Memory streams in a web service are not supported, but not alternative solution was provided.
ASKER
apeter said to use a byte array, but did not provide to turn that dataset to a byte array.
ASKER
apeter, you jogged my memory to point me to the correct solution, thanks for help and sorry to everyone else for the multiple postings.
ASKER
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>.Mem
WebApplication.WebService.
If I just pass my memory stream object I get the compile
error: Cannot Convert from 'System.IO.MemoryStream'
to 'WebApplication.WebService
Any ideas on why this isn't working? Or is there a better
way to do this???