わかりました問題は解決しました.....現在のコードは WebGetAttribute のみを処理していました:
class WebHttpBehavior2Ex : WebHttpBehavior
{
protected override IDispatchMessageFormatter GetReplyDispatchFormatter(OperationDescription operationDescription,
ServiceEndpoint endpoint)
{
WebGetAttribute webGetAttribute = operationDescription.Behaviors.Find<WebGetAttribute>();
DynamicResponseTypeAttribute mapAcceptedContentTypeToResponseEncodingAttribute =
operationDescription.Behaviors.Find<DynamicResponseTypeAttribute>();
if (webGetAttribute != null && mapAcceptedContentTypeToResponseEncodingAttribute != null) {
// We need two formatters, since we don't know what type we will need until runtime
webGetAttribute.ResponseFormat = WebMessageFormat.Json;
IDispatchMessageFormatter jsonDispatchMessageFormatter =
base.GetReplyDispatchFormatter(operationDescription, endpoint);
webGetAttribute.ResponseFormat = WebMessageFormat.Xml;
IDispatchMessageFormatter xmlDispatchMessageFormatter =
base.GetReplyDispatchFormatter(operationDescription, endpoint);
return new DynamicFormatter() {
jsonDispatchMessageFormatter = jsonDispatchMessageFormatter,
xmlDispatchMessageFormatter = xmlDispatchMessageFormatter };
}
return base.GetReplyDispatchFormatter(operationDescription, endpoint);
}
}
代わりに、以下のように WebGet 属性と WebInvoke 属性の両方を処理する必要があります。
public class WebHttpBehaviorEx : WebHttpBehavior
{
protected override IDispatchMessageFormatter GetReplyDispatchFormatter(OperationDescription operationDescription,
ServiceEndpoint endpoint)
{
WebGetAttribute webGetAttribute = operationDescription.Behaviors.Find<WebGetAttribute>();
WebInvokeAttribute webInvokeAttr = operationDescription.Behaviors.Find<WebInvokeAttribute>();
DynamicResponseTypeAttribute mapAcceptedContentTypeToResponseEncodingAttribute =
operationDescription.Behaviors.Find<DynamicResponseTypeAttribute>();
if (webGetAttribute != null && mapAcceptedContentTypeToResponseEncodingAttribute != null)
{
// We need two formatters, since we don't know what type we will need until runtime
webGetAttribute.ResponseFormat = WebMessageFormat.Json;
IDispatchMessageFormatter jsonDispatchMessageFormatter =
base.GetReplyDispatchFormatter(operationDescription, endpoint);
webGetAttribute.ResponseFormat = WebMessageFormat.Xml;
IDispatchMessageFormatter xmlDispatchMessageFormatter =
base.GetReplyDispatchFormatter(operationDescription, endpoint);
return new DynamicFormatter()
{
jsonDispatchMessageFormatter = jsonDispatchMessageFormatter,
xmlDispatchMessageFormatter = xmlDispatchMessageFormatter
};
}
else if (webInvokeAttr != null && mapAcceptedContentTypeToResponseEncodingAttribute != null)
{
// We need two formatters, since we don't know what type we will need until runtime
webInvokeAttr.ResponseFormat = WebMessageFormat.Json;
IDispatchMessageFormatter jsonDispatchMessageFormatter =
base.GetReplyDispatchFormatter(operationDescription, endpoint);
webInvokeAttr.ResponseFormat = WebMessageFormat.Xml;
IDispatchMessageFormatter xmlDispatchMessageFormatter =
base.GetReplyDispatchFormatter(operationDescription, endpoint);
return new DynamicFormatter()
{
jsonDispatchMessageFormatter = jsonDispatchMessageFormatter,
xmlDispatchMessageFormatter = xmlDispatchMessageFormatter
};
}
return base.GetReplyDispatchFormatter(operationDescription, endpoint);
}
}