if (contentType != ContentType)
throw new ProtocolException ("Only content type 'application/soap+msbin1' is allowed.");
-// FIXME: remove this extraneous buffering. It is somehow required for HTTP + binary encoding binding ...
-var tmpms = new MemoryStream ();
-var bytes = new byte [4096];
-int len;
-do {
- len = stream.Read (bytes, 0, bytes.Length);
- tmpms.Write (bytes, 0, len);
-} while (len > 0);
-tmpms.Seek (0, SeekOrigin.Begin);
-stream = tmpms;
+ // FIXME: remove this extraneous buffering. It is somehow required for HTTP + binary encoding binding. The culprit is probably in binary xml reader or writer, but not sure.
+ if (!stream.CanSeek) {
+ var tmpms = new MemoryStream ();
+ var bytes = new byte [4096];
+ int len;
+ do {
+ len = stream.Read (bytes, 0, bytes.Length);
+ tmpms.Write (bytes, 0, len);
+ } while (len > 0);
+ tmpms.Seek (0, SeekOrigin.Begin);
+ stream = tmpms;
+ }
return Message.CreateMessage (
XmlDictionaryReader.CreateBinaryReader (stream, soap_dictionary, owner != null ? owner.Owner.ReaderQuotas : new XmlDictionaryReaderQuotas (), session ? CurrentReaderSession : null),
using System;
using System.Collections.ObjectModel;
using System.IO;
+using System.Net.Sockets;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
}
}
+ [Test]
+ public void ConnectionTcpTransport ()
+ {
+ var host = new ServiceHost (typeof (Foo));
+ var bindingsvc = new CustomBinding (new BindingElement [] {
+ new BinaryMessageEncodingBindingElement (),
+ new TcpTransportBindingElement () });
+ host.AddServiceEndpoint (typeof (IFoo), bindingsvc, "net.tcp://localhost:37564/");
+ host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
+ host.Open (TimeSpan.FromSeconds (5));
+ try {
+ for (int i = 0; i < 2; i++) {
+ var bindingcli = new NetTcpBinding ();
+ bindingcli.Security.Mode = SecurityMode.None;
+ var cli = new ChannelFactory<IFooClient> (bindingcli, new EndpointAddress ("net.tcp://localhost:37564/")).CreateChannel ();
+ Assert.AreEqual ("test for echo", cli.Echo ("TEST FOR ECHO"), "#1");
+ var sid = cli.SessionId;
+ Assert.AreEqual (3000, cli.Add (1000, 2000), "#2");
+ Assert.AreEqual (sid, cli.SessionId, "#3");
+ cli.Close ();
+ }
+ } finally {
+ host.Close (TimeSpan.FromSeconds (5));
+ var t = new TcpListener (37564);
+ t.Start ();
+ t.Stop ();
+ }
+ }
+
+ [Test]
+ public void ConnectionHttpTransport ()
+ {
+ var host = new ServiceHost (typeof (Foo));
+ var bindingsvc = new CustomBinding (new BindingElement [] {
+ new BinaryMessageEncodingBindingElement (),
+ new HttpTransportBindingElement () });
+ host.AddServiceEndpoint (typeof (IFoo), bindingsvc, "http://localhost:37564/");
+ host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
+ host.Open (TimeSpan.FromSeconds (5));
+ try {
+ for (int i = 0; i < 2; i++) {
+ var bindingcli = new CustomBinding (new BindingElement [] {
+ new BinaryMessageEncodingBindingElement (),
+ new HttpTransportBindingElement () });
+ var cli = new ChannelFactory<IFooClient> (bindingcli, new EndpointAddress ("http://localhost:37564/")).CreateChannel ();
+ Assert.AreEqual ("test for echo", cli.Echo ("TEST FOR ECHO"), "#1");
+ var sid = cli.SessionId;
+ Assert.AreEqual (3000, cli.Add (1000, 2000), "#2");
+ Assert.AreEqual (sid, cli.SessionId, "#3");
+ cli.Close ();
+ }
+ } finally {
+ host.Close (TimeSpan.FromSeconds (5));
+ var t = new TcpListener (37564);
+ t.Start ();
+ t.Stop ();
+ }
+ }
+
+ public interface IFooClient : IFoo, IClientChannel
+ {
+ }
+
+ [ServiceContract]
+ public interface IFoo
+ {
+ [OperationContract]
+ string Echo (string msg);
+
+ [OperationContract]
+ uint Add (uint v1, uint v2);
+ }
+
+ class Foo : IFoo
+ {
+ public string Echo (string msg)
+ {
+ return msg.ToLower ();
+ }
+
+ public uint Add (uint v1, uint v2)
+ {
+ return v1 + v2;
+ }
+ }
+
void AssertNode (XmlReader reader, int depth, XmlNodeType nodeType, string prefix, string localName, string ns, string value, string label)
{
Assert.AreEqual (nodeType, reader.NodeType, label + ".NodeType");