繁体   English   中英

HTTP 415 无法处理消息,因为内容类型为“application/json; charset=utf-8' 不是预期的类型 'text/xml; 字符集=utf-8'

[英]HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'

我们有一个在 HTTPS 上运行良好的网络服务,但在 HTTPS 上显示 HTTP 415 错误。 因此,在 HTTP 下,我们可以毫无问题地进行 POST 请求发送和接收 JSON。 当我们在 HTTPS 下尝试同样的操作时,我们得到了服务期望 text/xml insteas of application/json 的错误。 关于在哪里看的任何建议?

如果这很重要,服务器正在使用自签名证书。

更新了绑定和行为

 <!-- Wcf Services Setting -->
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WsHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
        </binding>
        <binding name="SecureWsHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>
      <webHttpBinding>
        <binding name="WebHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
        </binding>
        <binding name="SecureWebHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
          <binding name="webBinding">
              <security mode="Transport">
              </security>
          </binding>
      </webHttpBinding>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IMainService" maxReceivedMessageSize="1048576"></binding>
        <binding name="BasicHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
            <security mode="None">
                <transport clientCredentialType="None" />
            </security>
        </binding>
        <binding name="SecureBasicHttpBinding" maxReceivedMessageSize="1048576">
          <readerQuotas maxArrayLength="1048576" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <webHttp DefaultOutgoingResponseFormat="json" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DvaMfs.WcfService">
        <useRequestHeadersForMetadataAddress>
                    <defaultPorts>
                        <add scheme="https" port="443" />
                    </defaultPorts>
                </useRequestHeadersForMetadataAddress>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

服务看起来像这样

<service name="DvaMfs.WcfService.ProductService" behaviorConfiguration="DvaMfs.WcfService">
    <endpoint name="ProductServiceEndPoint" address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="DvaMfs.WcfService.IProductService" />
    <endpoint name="ProductServiceAjaxEndPoint" address="ajax" binding="webHttpBinding" bindingConfiguration="WebHttpBinding" behaviorConfiguration="AjaxBehavior" contract="DvaMfs.WcfService.IProductService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint name="ProductServiceSecureEndPoint" address="ProductServiceSecure" binding="basicHttpBinding" bindingConfiguration="SecureBasicHttpBinding" contract="DvaMfs.WcfService.IProductService" />
    <endpoint name="ProductServiceAjaxSecureEndPoint" address="ProductServiceSecureajax" binding="webHttpBinding" bindingConfiguration="SecureWebHttpBinding" behaviorConfiguration="AjaxBehavior" contract="DvaMfs.WcfService.IProductService" />
  </service>

更新 2这是失败的端点之一:

<endpoint name="DataServiceSecureEndPoint" address="" binding="basicHttpBinding"
bindingConfiguration="SecureBasicHttpBinding" contract="DvaMfs.WcfService.IDataService" />

WCF可以为HTTP或HTTP提供不同的端点。 我认为这是问题,所以我会把它作为一个“答案”(我希望它可以帮到你):

您的端点名称=“ProductServiceEndPoint”address =“”它在您的基地址公开。

您的端点名称=“ProductServiceSecureEndPoint”address =“ProductServiceSecure” bindingConfiguration =“SecureBasicHttpBinding”它在基础“base_address] / ProductServiceSecure”中公开。

所以这个终点:

  • endpoint name =“DataServiceSecureEndPoint”address =“”binding =“basicHttpBinding” bindingConfiguration =“SecureBasicHttpBinding”

这是不正确的,因为地址可能是“ProductServiceSecure”

basicHttpBinding不能与JSON一起使用。 如果要使用JSON,请将basicHttpBinding(SOAP)更改为webHttpBinding(REST)。

对于这个问题的解决方案是,在您的请求/响应模型中,有一些类没有默认构造函数,它是无参数的。

最后,我们的后端开发人员更改了端点地址字段并将其路由到特定路径(而不是address =“”)以测试它是否正常工作。 显然,根据他的说法,HTTP和HTTPS端点试图使用相同的地址,但是没有用。 所以他最后评论了HTTP端点并设置了HTTPS端点的地址。

我不知道这是否有意义,因为我不知道WCF。 对我来说,对Apache服务器有一些了解,似乎你应该能够指定一个端点,它不应该基于/链接到用于连接它的协议。

configfile在服务标签名称=“namespace.Service”添加则在端点标签

address="" behaviorConfiguration="web" binding="webHttpBinding"
     contract="namespace.IService"

并在IService接口中

[WebInvoke(Method = "POST", UriTemplate = "functionname", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP / 1.1 415无法处理消息,因为内容类型为&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;text / xml; 字符集= UTF-8&#39; 无法处理消息,因为内容类型为 &#39;application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; 无法处理该消息,因为内容类型“ application / xml”不是预期的类型“ application / soap + xml”; 字符集= utf-8&#39; 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8) 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF 内容类型 text/xml; 响应消息的 charset=&quot;utf-8&quot; 与绑定的内容类型不匹配 (text/xml; charset=utf-8) 内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8) WCF错误:(415)内容类型&#39;application / x-www-form-urlencoded&#39;不是预期类型&#39;application / soap + xml; 字符集= UTF-8&#39; WCF成员资格提供程序引发错误:内容类型&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;application / soap + xml; 字符集= UTF-8&#39; WCF SOAP服务无法处理该消息,因为它发送多部分消息并且需要&#39;text / xml; charset = utf-8&#39;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM