[英]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'
[英]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”中公開。
所以這個終點:
這是不正確的,因為地址可能是“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.