// endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add (something);
}
- [MonoTODO ("where should I set reply client formatter?")]
public virtual void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
AddClientErrorInspector (endpoint, clientRuntime);
foreach (ClientOperation oper in clientRuntime.Operations) {
- oper.Formatter = GetRequestClientFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint);
- //oper.Formatter = GetReplyClientFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint); // FIXME: see MonoTODO.
+ var req = GetRequestClientFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint);
+ var res = GetReplyClientFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint);
+ oper.Formatter = new ClientPairFormatter (req, res);
}
}
- [MonoTODO ("where should I set reply dispatch formatter?")]
public virtual void ApplyDispatchBehavior (ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.DispatchRuntime.OperationSelector = GetOperationSelector (endpoint);
AddServerErrorHandlers (endpoint, endpointDispatcher);
foreach (DispatchOperation oper in endpointDispatcher.DispatchRuntime.Operations) {
- oper.Formatter = GetRequestDispatchFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint);
- //oper.Formatter = GetReplyDispatchFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint); // FIXME: see MonoTODO.
+ var req = GetRequestDispatchFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint);
+ var res = GetReplyDispatchFormatter (endpoint.Contract.Operations.Find (oper.Name), endpoint);
+ oper.Formatter = new DispatchPairFormatter (req, res);
+ }
+ }
+
+ internal class ClientPairFormatter : IClientMessageFormatter
+ {
+ public ClientPairFormatter (IClientMessageFormatter request, IClientMessageFormatter reply)
+ {
+ this.request = request;
+ this.reply = reply;
+ }
+
+ IClientMessageFormatter request, reply;
+
+ public Message SerializeRequest (MessageVersion messageVersion, object [] parameters)
+ {
+ return request.SerializeRequest (messageVersion, parameters);
+ }
+
+ public object DeserializeReply (Message message, object [] parameters)
+ {
+ return reply.DeserializeReply (message, parameters);
+ }
+ }
+
+ internal class DispatchPairFormatter : IDispatchMessageFormatter
+ {
+ public DispatchPairFormatter (IDispatchMessageFormatter request, IDispatchMessageFormatter reply)
+ {
+ this.request = request;
+ this.reply = reply;
+ }
+
+ IDispatchMessageFormatter request;
+ IDispatchMessageFormatter reply;
+
+ public void DeserializeRequest (Message message, object [] parameters)
+ {
+ request.DeserializeRequest (message, parameters);
+ }
+
+ public Message SerializeReply (MessageVersion messageVersion, object [] parameters, object result)
+ {
+ return reply.SerializeReply (messageVersion, parameters, result);
}
}
: base (operation, endpoint, converter, behavior)
{
}
+
+ public override object DeserializeReply (Message message, object [] parameters)
+ {
+ throw new NotSupportedException ();
+ }
}
internal class ReplyClientFormatter : WebClientMessageFormatter
: base (operation, endpoint, converter, behavior)
{
}
+
+ public override Message SerializeRequest (MessageVersion messageVersion, object [] parameters)
+ {
+ throw new NotSupportedException ();
+ }
}
internal class RequestDispatchFormatter : WebDispatchMessageFormatter
{
}
- public Message SerializeRequest (MessageVersion messageVersion, object [] parameters)
+ public virtual Message SerializeRequest (MessageVersion messageVersion, object [] parameters)
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
return ret;
}
- public object DeserializeReply (Message message, object [] parameters)
+ public virtual object DeserializeReply (Message message, object [] parameters)
{
if (parameters == null)
throw new ArgumentNullException ("parameters");
using System;
+using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
namespace MonoTests.System.ServiceModel.Description
{
+ public class WebHttpBehaviorExt : WebHttpBehavior
+ {
+ public IClientMessageFormatter DoGetReplyClientFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
+ {
+ return GetReplyClientFormatter (operationDescription, endpoint);
+ }
+
+ public IClientMessageFormatter DoGetRequestClientFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
+ {
+ return GetRequestClientFormatter (operationDescription, endpoint);
+ }
+
+ public IDispatchMessageFormatter DoGetReplyDispatchFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
+ {
+ return GetReplyDispatchFormatter (operationDescription, endpoint);
+ }
+
+ public IDispatchMessageFormatter DoGetRequestDispatchFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
+ {
+ return GetRequestDispatchFormatter (operationDescription, endpoint);
+ }
+
+ public event Action<ServiceEndpoint, ClientRuntime> ApplyClientBehaviorInvoked;
+
+ public override void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime client)
+ {
+ base.ApplyClientBehavior (endpoint, client);
+ if (ApplyClientBehaviorInvoked != null)
+ ApplyClientBehaviorInvoked (endpoint, client);
+ }
+ }
+
[TestFixture]
public class WebHttpBehaviorTest
{
}
[Test]
- [Category("NotWorking")]
public void AddBiningParameters ()
{
var se = CreateEndpoint ();
Assert.AreEqual (0, ed.DispatchRuntime.Operations.Count, "#4-0"); // hmm... really?
}
+ [Test]
+ public void GetMessageFormatters ()
+ {
+ var se = CreateEndpoint ();
+ var od = se.Contract.Operations [0];
+ var b = new WebHttpBehaviorExt ();
+ Assert.IsNotNull (b.DoGetRequestClientFormatter (od, se), "#1");
+ Assert.IsNotNull (b.DoGetReplyClientFormatter (od, se), "#2");
+ Assert.IsNotNull (b.DoGetRequestDispatchFormatter (od, se), "#3");
+ Assert.IsNotNull (b.DoGetReplyDispatchFormatter (od, se), "#4");
+ }
+
+ [Test]
+ public void RequestClientFormatter ()
+ {
+ var se = CreateEndpoint ();
+ var od = se.Contract.Operations [0];
+ var b = new WebHttpBehaviorExt ();
+ var rcf = b.DoGetRequestClientFormatter (od, se);
+ var msg = rcf.SerializeRequest (MessageVersion.None, new object [] {"foo"});
+ var hp = msg.Properties [HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
+ Assert.IsNotNull (hp, "#1");
+ Assert.IsTrue (msg.IsEmpty, "#2");
+ Assert.AreEqual (String.Empty, hp.QueryString, "#3");
+ var mb = msg.CreateBufferedCopy (1000);
+ try {
+ rcf.DeserializeReply (mb.CreateMessage (), new object [0]);
+ Assert.Fail ("It should not support reply deserialization");
+ } catch (NotSupportedException) {
+ }
+ }
+
+ [Test]
+ public void RequestClientFormatter2 ()
+ {
+ var se = CreateEndpoint ();
+ var od = se.Contract.Operations [0];
+ var b = new WebHttpBehaviorExt ();
+ IClientMessageFormatter rcf = null;
+ b.ApplyClientBehaviorInvoked += delegate (ServiceEndpoint e, ClientRuntime cr) {
+ rcf = cr.Operations [0].Formatter;
+ };
+ se.Behaviors.Add (b);
+ var ch = new WebChannelFactory<IMyServiceClient> (se).CreateChannel ();
+ var msg = rcf.SerializeRequest (MessageVersion.None, new object [] {"foo"});
+ var hp = msg.Properties [HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
+ Assert.IsNotNull (hp, "#1");
+ Assert.IsTrue (msg.IsEmpty, "#2");
+ Assert.AreEqual (String.Empty, hp.QueryString, "#3");
+ //var mb = msg.CreateBufferedCopy (1000);
+
+ // TODO: test DeserializeReply too (it is supported unlike above).
+ }
+
[ServiceContract]
public interface IMyService
{
string Echo (string input);
}
+ public interface IMyServiceClient : IMyService, IClientChannel
+ {
+ }
+
public class MyService: IMyService
{
[OperationBehavior]