【问题标题】:Why does WCF return code 400 when content-type:application/xml header is present?当 content-type:application/xml 标头存在时,为什么 WCF 返回代码 400?
【发布时间】:2011-12-06 10:10:21
【问题描述】:

当请求中包含 content-type:application/xml 标头时,我有一个 REST WCF 服务返回错误请求 (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。

【问题讨论】:

    标签: xml wcf


    【解决方案1】:

    您可能需要在端点中设置WebContentTypeMapper - 请参阅http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-receiving-arbitrary-data.aspx 的帖子中的更多详细信息。您可以通过编程方式添加它(如帖子所示),或使用 &lt;bindings&gt;/&lt;webHttpBinding&gt;/&lt;binding&gt; 元素中的 contentTypeMapper 属性。

    【讨论】:

      猜你喜欢
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多