简体   繁体   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'

We have a webservice that works fine on HTTPS but shows the HTTP 415 error on HTTPS.我们有一个在 HTTPS 上运行良好的网络服务,但在 HTTPS 上显示 HTTP 415 错误。 So, under HTTP, we can make a POST request sending and receiving JSON without issue.因此,在 HTTP 下,我们可以毫无问题地进行 POST 请求发送和接收 JSON。 When we try the same under HTTPS we got the error that the service is expecting text/xml insteas of application/json.当我们在 HTTPS 下尝试同样的操作时,我们得到了服务期望 text/xml insteas of application/json 的错误。 Any suggestion on where to look?关于在哪里看的任何建议?

The server is using a self signed certificate if that matters.如果这很重要,服务器正在使用自签名证书。

Updated with bindings and behaviors更新了绑定和行为

 <!-- 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>

services look like this服务看起来像这样

<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>

Update 2 This is one of the endpoints failing:更新 2这是失败的端点之一:

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

WCF can have different endpoints for HTTP or HTTPs. WCF可以为HTTP或HTTP提供不同的端点。 I think this is the problem, so I will put it as an "answer" (I hope it helps you): 我认为这是问题,所以我会把它作为一个“答案”(我希望它可以帮到你):

Your endpoint name="ProductServiceEndPoint" address="" it's exposed at your base address. 您的端点名称=“ProductServiceEndPoint”address =“”它在您的基地址公开。 OK

Your endpoint name="ProductServiceSecureEndPoint" address="ProductServiceSecure" bindingConfiguration="SecureBasicHttpBinding" it's exposed at base "base_address]/ProductServiceSecure". 您的端点名称=“ProductServiceSecureEndPoint”address =“ProductServiceSecure” bindingConfiguration =“SecureBasicHttpBinding”它在基础“base_address] / ProductServiceSecure”中公开。

So this endpoint: 所以这个终点:

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

It's incorrect, because the address may be "ProductServiceSecure" 这是不正确的,因为地址可能是“ProductServiceSecure”

The basicHttpBinding can not work with JSON. basicHttpBinding不能与JSON一起使用。 Change the basicHttpBinding (SOAP) to webHttpBinding (REST) if you want to use JSON. 如果要使用JSON,请将basicHttpBinding(SOAP)更改为webHttpBinding(REST)。

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

At the end our back-end developer changed the endpoint address field and routed it to specific paths (instead of address="") to test if it was working and it was. 最后,我们的后端开发人员更改了端点地址字段并将其路由到特定路径(而不是address =“”)以测试它是否正常工作。 Apparently, according to what he said, the HTTP and HTTPS endpoints were trying to use the same address and that wasn't working. 显然,根据他的说法,HTTP和HTTPS端点试图使用相同的地址,但是没有用。 So he finally commented the HTTP endpoints and set the address for the HTTPS ones. 所以他最后评论了HTTP端点并设置了HTTPS端点的地址。

I don't know if that make much sense since I have no idea about WCF. 我不知道这是否有意义,因为我不知道WCF。 To me, having some knowledge on Apache servers, it seems that you should be able to specify an endpoint and it shouldn't be based on/linked to the protocol used for connecting to it. 对我来说,对Apache服务器有一些了解,似乎你应该能够指定一个端点,它不应该基于/链接到用于连接它的协议。

In configfile add in service tag name="namespace.Service" then in endpoint tagconfigfile在服务标签名称=“namespace.Service”添加则在端点标签

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

and in IService interface并在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; - HTTP/1.1 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理消息,因为内容类型为 &#39;application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理该消息,因为内容类型“ application / xml”不是预期的类型“ application / soap + xml”; 字符集= utf-8&#39; - Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 ' 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8), WCF 内容类型 text/xml; 响应消息的 charset=&quot;utf-8&quot; 与绑定的内容类型不匹配 (text/xml; charset=utf-8) - The content type text/xml; charset=“utf-8” of the response message does not match the content type of the binding (text/xml; charset=utf-8) 内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8) WCF错误:(415)内容类型&#39;application / x-www-form-urlencoded&#39;不是预期类型&#39;application / soap + xml; 字符集= UTF-8&#39; - WCF ERROR: (415) content type 'application/x-www-form-urlencoded' was not the expected type 'application/soap+xml; charset=utf-8' WCF成员资格提供程序引发错误:内容类型&#39;application / json; charset = utf-8&#39;不是预期的类型&#39;application / soap + xml; 字符集= UTF-8&#39; - WCF Membership Provider throws error: content type 'application/json; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8' WCF SOAP服务无法处理该消息,因为它发送多部分消息并且需要&#39;text / xml; charset = utf-8&#39; - WCF SOAP service cannot process the message because it sends multipart message and expects 'text/xml; charset=utf-8'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM