Convert a SOAP Message from a Stream
I have a Windows mobile .NET 3.5 compact framework application on a handheld device which connects to a SOAP Server requiring WS-Security in the message header.
Since WSE doesn't work on compact framework, I managed to create a Custom Binding to communicate with the server and receive messages.
In the Custom Binding Encoder (a MessageEncoder), I need to override some methods to read the received message :
public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
{
bufferManager.ReturnBuffer(buffer.Array);
MemoryStream memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count);
// to quickly see the content of the message
string s = Encoding.Default.GetString(buffer.Array, 0, buffer.Array.Count());
Console.WriteLine("gna " + s);
Message message = this.ReadMessage(memoryStream, buffer.Array.Length, null);
return message;
}
public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
{
XmlReader reader = XmlReader.Create(stream);
return Message.CreateMessage(reader, maxSizeOfHeaders, this.MessageVersion);
}
The second method doesn't compile in compact framework! According to the definition of the CreateMessage
method, compact framework allows only a few possibilities : using a BodyWriter
or a XmlObjectSerializer
instead of simply using a XmlReader
as provided in the above standard code. The problem is that these two objects are abstract and need to be instanciated in order to be used by the function.
So is there some way to create a Message from a Stream in compact framework? Did somebody have the same problem? Are there any pre-build objects I can use to replace these BodyWriter
or XmlObjectSerializer
?
上一篇: 如何将字节数组转换为字符串
下一篇: 从流中转换SOAP消息