単一の ServiceContract 内で定義された一連の操作があり、そのうちの 2 つが、MSDN ドキュメントで概説されているように、Stream 本体を含む MessageContract を直接取得して返すように切り替えられました。これをテストしたところ、問題なく動作しているように見えますが、同じ 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:
何が起こっているのかを理解していれば、MessageContract ベースの操作を容易にするためにサーバーとクライアントの両方で TransferMode を両方向に Streamed に設定したことが問題だと思いますが、これは以前に機能していた非 MessageContract ベースの操作を壊しているに違いありませんストリーミングのものを紹介しました。
次に、おそらく次の2つのオプションしかありません。
- このサービス内のすべての操作コントラクトを書き直して、MessageContract ベースになるようにし、おそらく本体のストリームを公開するようにします。この時点で、Stream が必要なのか、それとも単に null に設定したり、メッセージから完全に除外したりできるのかはわかりません。
- 転送モードに基づいて、操作コントラクトを個別の ServiceContracts に分割します。
これは正確に聞こえますか?他のオプションはありますか?OperationContract ごとに TransferMode を指定する方法があるかどうかを調べましたが、バインディングの設定であるため、これを行う方法が見つかりません。また、OperationContract ごとに個別のバインディングを指定する方法がわかりません。 .
公開する必要がある一連のサービスを進めるための最良のオプションは何ですか?