Issue with WCF + NetTcpBinding + MessageContract + MemoryStream

Hello Everybody,

Im facing a strange problem with one of my WCF service. It uses TCP/IP binding. Return value and parameter
are MessageContracts.

Parameter :

[MessageContract]

publicclassMsgContract1

{

Stream data;

[MessageBodyMember]

publicStream Data

{

get {return data;}

set { data =value;}

}

}

Return Value :

[MessageContract]

publicclassMsgContractReturn

{

string result =string.Empty ;

[MessageHeader]

publicstring Result

{

get {return result; }

set { result =value; }

}

}

Service :

publicMsgContractReturn MyOperation3(MsgContract1 dataContractValue)

{

MsgContractReturn msgret =newMsgContractReturn();

try

{

long t = dataContractValue.Data.Length;

byte[] data =newbyte[1000];

dataContractValue.Data.Read(data, 0, data.Length);

msgret.Result =Encoding.UTF8.GetString(data);

}

catch(Exception ex)

{

throw ex;

}

return msgret;

}


When 'Data' field of MsgContract1 is FileStream, service works properly. But when I try to use MemoryStream, service
doesnt receive' Data' field properly. Its giving an exception when accessing Length property and 'Data' is empty. Please help.

Thanks a lot

Hantana


[3082 byte] By [hantana] at [2008-1-4]
# 1

You are saying that your service could get a request for a MemoryStream (some object) that is null - it does not exist - and then your service will try to serialize and send a null value as a stream?

TrevorW at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2

what exception ?

when you use the MemoryStream on the client, you will probably pass in a memorystream who's position is at the end ? would setting the stream position to 0 help ?

/Allan

Allan-Nielsen at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3

Hi TrevorW,

Request contains an empty stream. But stream is not null.

Thanks

hantana

hantana at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4

Hi Allan,

When I try to check Length property it gives "Specified method is not supported." exception. Same exception was given

when setting position to 0.

Thanks

hantana

hantana at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5

What value is flowing on the wire, I wonder?

Can you share the client code that uses the MemoryStream?

BrianMcNamara-MSFT at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 6

I mean set the position to 0 on the client side, not on the server side ?

share the code as Brian says.

Allan-Nielsen at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 7
Hi Allan,

Yes. You are correct, It works fine now. Thanks a lot. But there is no way of validating emptiness of stream.

Regards
Hantana

hantana at 2007-10-11 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified