HTTP 415 Cannot process the message because the content type 'application / json; charset = utf-8' was not the expected type text / xml; encoding = UTF-8 '

We have a web service that works great on HTTPS but shows an HTTP error 415 on HTTPS. Thus, over HTTP, we can make a POST request by sending and receiving JSON without any problems. When we try to do the same with HTTPS, we get the error message expected by the text / xml application / json service. Any suggestion on where to look?

The server uses a self-signed certificate, if that matters.

Updated with bindings and behavior

<!-- 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 are as follows

 <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 failed endpoints:

 <endpoint name="DataServiceSecureEndPoint" address="" binding="basicHttpBinding" bindingConfiguration="SecureBasicHttpBinding" contract="DvaMfs.WcfService.IDataService" /> 
+5
source share
4 answers

WCF can have different endpoints for HTTP or HTTP. I think this is a problem, so I will put it as an β€œanswer” (I hope this helps you):

The endpoint name = "ProductServiceEndPoint" address = "", which it expands to your base address. Ok

Endpoint name = "ProductServiceSecureEndPoint" address = "ProductServiceSecure" bindingConfiguration = "SecureBasicHttpBinding" , which she opened in the database "base_address] / ProductServiceSecure".

So this endpoint:

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

This is incorrect because the address may be "ProductServiceSecure"

+4
source

BaseHttpBinding cannot work with JSON. Change basicHttpBinding (SOAP) to webHttpBinding (REST) ​​if you want to use JSON.

+1
source

In the end, our internal developer changed the endpoint address field and redirected it to certain paths (instead of address = "") to check if it worked, and that was. Apparently, according to him, the HTTP and HTTPS endpoints tried to use the same address and it did not work. So he finally commented on the HTTP endpoints and set the address for HTTPS.

I do not know if this makes sense, since I have no idea about WCF. For me, having some knowledge on Apache servers, it seems that you should be able to specify the endpoint and should not be based on / associated with the protocol used to connect to it.

0
source

For this problem, the solution is that in your request / response model there is some class that by default does not have a constructor that is without parameters.

0
source

Source: https://habr.com/ru/post/1205753/


All Articles