2

我有一组在单个 ServiceContract 中定义的操作,现在其中两个已切换为直接获取和返回 MessageContracts,其中包含 MSDN 文档中概述的 Stream 主体。我已经对此进行了测试,它似乎工作正常,但是现在当我在同一个 ServiceContract 中调用我的其他操作时,它采用简单的 RPC 样式参数和返回类型,我得到以下异常。

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: 

如果我了解发生了什么,我认为问题在于我已将服务器和客户端的 TransferMode 在两个方向上都设置为 Streamed,以促进基于 MessageContract 的操作,但这一定会破坏我之前工作的非基于 MessageContract 的操作我介绍了流媒体。

那么也许我只有这两个选择:

  1. 在此服务中重新编写我的所有操作合同,以便它们基于 MessageContract,也许还可以为主体公开一个 Stream。在这一点上,我不确定是否需要 Stream,或者我是否可以将其设置为 null 或将其完全从消息中排除。
  2. 根据传输模式将我的运营合同分成单独的 ServiceContract。

这听起来准确吗?还有其他选择吗?我已经研究过是否有办法为每个 OperationContract 指定 TransferMode,但我找不到任何方法可以做到这一点,因为它是绑定的设置,我不知道有任何方法可以为每个 OperationContract 指定单独的绑定.

推进我需要公开的一组服务的最佳选择是什么?

4

0 回答 0