I have a set of operations that are defined within a single ServiceContract and now two of them have been switched over to take and return MessageContracts directly which contain a Stream body as outlined within the MSDN documentation. I've tested this and it seems to work fine however now when I call my other operations within the same ServiceContract which take simple RPC style parameters and return types I get the following exception.
System.ServiceModel.ProtocolException occurred
Message=The remote server returned an unexpected response: (400) Bad Request.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
...
InnerException: System.Net.WebException
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
InnerException:
If I understand what is going on I think the problem is that I have set the TransferMode to Streamed in both directions for both the server and the client to facilitate the MessageContract based operations but this must be breaking my non MessageContract based operations that were working before I introduced the streaming ones.
Then perhaps I only have these two options:
- Re-write all of my operation contracts within this service so that they are MessageContract based and perhaps also so that they expose a Stream for the body. At this point I'm not sure if the Stream would be required or if I could just set it to null or exclude it from the message altogether.
- Separate my operation contracts into separate ServiceContracts based on their transfer mode.
Does this sound accurate? Are there any other options? I've looked into whether there is a way to specify the TransferMode per OperationContract but I can't find any way to do this as it is a setting on the binding and I'm not aware of any way to specify separate bindings per OperationContract.
What are my best options for going forward with the set of services I need to expose?