我有一个REST WCF服务,当请求中包含content-type:application / xml标头时,它返回Bad Request(400)响应。当我删除该标头时,服务会正确响应。
服务定义:
[ServiceContract]
public interface IRestService
{
[OperationContract]
[WebInvoke(UriTemplate = "/methodName", BodyStyle=WebMessageBodyStyle.Bare)]
XElement MethodName(Stream stream);
}
端点配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="1024000"/>
</webHttpBinding>
</bindings>
<services>
<service name="RestService">
<endpoint address="" behaviorConfiguration="webHttp" binding="webHttpBinding"
name="webHttpBinding" contract="IRestService" />
</service>
</services>
</system.serviceModel>
有效负载是有效的XML。
答案 0 :(得分:2)
您可能需要在端点中设置WebContentTypeMapper
- 请参阅http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx帖子中的详细信息。您可以通过编程方式(如帖子中所示)或使用contentTypeMapper
元素中的<bindings>/<webHttpBinding>/<binding>
属性添加它。