2014-10-29 120 views
4

我們有一個在HTTPS上正常工作但在HTTPS上顯示HTTP 415錯誤的web服務。所以,在HTTP下,我們可以發出一個POST請求發送和接收JSON而沒有問題。當我們在HTTPS下嘗試使用相同的服務時,我們得到的錯誤是服務期望application/json的text/xml insteas。任何建議在哪裏看?HTTP 415由於內容類型'application/json; charset = utf-8'不是預期的類型'text/xml; charset = utf-8'

服務器使用簽名的證書,如果該事項自我。

綁定的更新和行爲

<!-- 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" /> 
+0

假設,請提供bindingConfiguration和行爲。這是你錯誤的關鍵,我認爲 – Caveman 2014-10-29 08:04:01

+0

順便說一句,我嘗試了所有與SO相同的錯誤沒有任何運氣的問題的所有建議。 – momo 2014-10-29 08:33:50

+0

@CapitanCavernícola用配置文件的一部分更新了問題。 – momo 2014-10-29 08:35:25

回答

4

WCF可以對HTTP或HTTPS不同的端點。 我覺得這是一個問題,所以我會把它作爲一個「答案」(我希望它可以幫助你):

端點名稱=「ProductServiceEndPoint」地址=「」它在你的基地地址暴露出來。 OK

端點名稱= 「ProductServiceSecureEndPoint」 地址= 「ProductServiceSecure」 bindingConfiguration = 「SecureBasicHttpBinding」它暴露在基地 「BASE_ADDRESS]/ProductServiceSecure」。

所以這個端點:

  • 端點名稱= 「DataServiceSecureEndPoint」 地址= 「」 綁定= 「basicHttpBinding的」 bindingConfiguration = 「SecureBasicHttpBinding」

這是不正確的,因爲地址可能是「ProductServiceSecure」

+0

它是有道理的,我接受它希望它會在未來幫助別人解決這個問題。 Saludos ;-) – momo 2014-10-31 02:28:59

1

basicHttpBinding無法使用JSON。如果您想使用JSON,請將basicHttpBinding(SOAP)更改爲webHttpBinding(REST)。

+0

那麼你會如何解釋,相同的確切代碼在HTTP上使用JSON工作正常?只有在使用HTTPS執行POST時纔會發生此問題。我不明白爲什麼 – momo 2014-10-29 09:30:17

+1

我會說你正在檢查錯誤的端點或者調用sarvice沒有請求json,因爲basicHttpBinding根本不支持json。 – 2014-10-29 09:44:33

+1

相同的確切代碼不能,我想你無論如何設置代理。對於更多測試:您可以試試'僅'''而不是'',並在HTTPS中註釋您沒有使用的端點? – Caveman 2014-10-29 09:53:41

0

在結束我們的後端開發人員改變了端點地址字段並將其路由到特定的路徑(而不是地址=「」),以測試它的工作,它是。很明顯,根據他所說的,HTTP和HTTPS端點試圖使用相同的地址,並且不起作用。所以他最終評論了HTTP端點併爲HTTPS設置了地址。

如果太大的意義,因爲我不知道WCF的想法,我不知道。對我而言,在Apache服務器上有一定的知識,似乎你應該能夠指定一個端點,並且它不應該基於/鏈接到用於連接它的協議。

0

對於這個問題的解決方案是,在你的請求/響應模型有一定的階級誰沒有t是默認的無參數構造函數。您正在使用WCF

相關問題