は、私は同じエラーメッセージの中に、異なるシナリオで実行されていました。私は、XMLだけをサポートするWCF WebサービスにJSONサポートを追加していました。
具体的には、JSONのエラーメッセージオブジェクトも返すことにしました。 私はSystem.ServiceModel.Dispatcher.IErrorHandler
を実装していたクラスを持っていました。 ProvideFault
メソッドの中で、私は `WebBodyFormateMessagePropertyをacceptヘッダーで渡された内容に基づいて対応するもの、XMLまたはJSONに設定しました。それに応じてコンテンツタイプも設定していました。私が行方不明になったことは
Dim webBodyFormatMessageProp As Channels.WebBodyFormatMessageProperty
Dim contentType As String
Dim serializer As XmlObjectSerializer
If WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json Then
webBodyFormatMessageProp = New System.ServiceModel.Channels.WebBodyFormatMessageProperty(System.ServiceModel.Channels.WebContentFormat.Json)
contentType = "application/json"
serializer = New DataContractJsonSerializer(GetType(MyErroClass))
Else
webBodyFormatMessageProp = New System.ServiceModel.Channels.WebBodyFormatMessageProperty(System.ServiceModel.Channels.WebContentFormat.Xml)
contentType = "text/xml"
serializer = New DataContractSerializer(GetType(MyErroClass))
End If
Dim detail = faultException.[GetType]().GetProperty("Detail").GetGetMethod().Invoke(faultException, Nothing)
fault = System.ServiceModel.Channels.Message.CreateMessage(version, "", detail, serializer)
fault.Properties.Add(System.ServiceModel.Channels.WebBodyFormatMessageProperty.Name, webBodyFormatMessageProp)
Dim httpResponseMessageProp = New System.ServiceModel.Channels.HttpResponseMessageProperty()
httpResponseMessageProp.Headers(System.Net.HttpResponseHeader.ContentType) = contentType
httpResponseMessageProp.StatusCode = System.Net.HttpStatusCode.OK
httpResponseMessageProp.StatusDescription = [error].Message
fault.Properties.Add(System.ServiceModel.Channels.HttpResponseMessageProperty.Name, httpResponseMessageProp)
各ケースの正しいシリアライザを使用していたVB.netを謝るが、それは、私が現在働いているものです。