我正在使用 WCF Extensibilty,并且创建了一个IClientMessageFormatter,它通过 Json-RPC 序列化请求。代码是这样的:
public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
{
string jsonText = SerializeJsonRequestParameters(parameters);
// Compose message
Message message = Message.CreateMessage(messageVersion, _clientOperation.Action, new JsonRpcBodyWriter(Encoding.UTF8.GetBytes(jsonText)));
message.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw));
_address.ApplyTo(message);
HttpRequestMessageProperty reqProp = new HttpRequestMessageProperty();
reqProp.Headers[HttpRequestHeader.ContentType] = "application/json";
message.Properties.Add(HttpRequestMessageProperty.Name, reqProp);
UriBuilder builder = new UriBuilder(message.Headers.To);
builder.Query = string.Format("jsonrpc={0}", HttpUtility.UrlEncode(jsonText));
message.Headers.To = builder.Uri;
message.Properties.Via = builder.Uri;
return message;
}
我试图使用 HttpRequestMessageProperty 强制 WCF 使用 GET http 动词,但设置以下内容:
reqProp.Method = "GET";
导致 WCF 引发 System.Net.ProtocolViolationException。谁能告诉我我做错了什么?