HTTP 415由于内容类型'application/json; charset = utf-8'不是预期的类型'text/xml; charset = utf-8'
我们有一个在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" />
WCF可以对HTTP或HTTPS不同的端点。 我觉得这是一个问题,所以我会把它作为一个“答案”(我希望它可以帮助你):
你端点名称=“ProductServiceEndPoint”地址=“”它在你的基地地址暴露出来。 OK
你端点名称= “ProductServiceSecureEndPoint” 地址= “ProductServiceSecure” bindingConfiguration = “SecureBasicHttpBinding”它暴露在基地 “BASE_ADDRESS]/ProductServiceSecure”。
所以这个端点:
- 端点名称= “DataServiceSecureEndPoint” 地址= “” 绑定= “basicHttpBinding的” bindingConfiguration = “SecureBasicHttpBinding”
这是不正确的,因为地址可能是“ProductServiceSecure”
它是有道理的,我接受它希望它会在未来帮助别人解决这个问题。 Saludos ;-) – momo 2014-10-31 02:28:59
basicHttpBinding无法使用JSON。如果您想使用JSON,请将basicHttpBinding(SOAP)更改为webHttpBinding(REST)。
在结束我们的后端开发人员改变了端点地址字段并将其路由到特定的路径(而不是地址=“”),以测试它的工作,它是。很明显,根据他所说的,HTTP和HTTPS端点试图使用相同的地址,并且不起作用。所以他最终评论了HTTP端点并为HTTPS设置了地址。
如果太大的意义,因为我不知道WCF的想法,我不知道。对我而言,在Apache服务器上有一定的知识,似乎你应该能够指定一个端点,并且它不应该基于/链接到用于连接它的协议。
对于这个问题的解决方案是,在你的请求/响应模型有一定的阶级谁没有t是默认的无参数构造函数。您正在使用WCF
假设,请提供bindingConfiguration和行为。这是你错误的关键,我认为 – Caveman 2014-10-29 08:04:01
顺便说一句,我尝试了所有与SO相同的错误没有任何运气的问题的所有建议。 – momo 2014-10-29 08:33:50
@CapitanCavernícola用配置文件的一部分更新了问题。 – momo 2014-10-29 08:35:25