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