11

We have a webservice that works fine on HTTPS but shows the HTTP 415 error on HTTPS. So, under HTTP, we can make a POST request sending and receiving JSON without issue. When we try the same under HTTPS we got the error that the service is expecting text/xml insteas of application/json. Any suggestion on where to look?

The server is using a self signed certificate if that matters.

Updated with bindings and behaviors

 <!-- 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 look like this

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

<endpoint name="DataServiceSecureEndPoint" address="" binding="basicHttpBinding"
bindingConfiguration="SecureBasicHttpBinding" contract="DvaMfs.WcfService.IDataService" />
momo
  • 3,404
  • 6
  • 37
  • 66
  • Assuming you're using WCF, please provide the bindingConfiguration and behaviors. This is the key of you're error, I think – Morcilla de Arroz Oct 29 '14 at 08:04
  • BTW, I tried all the suggestions for all the questions with this same error on SO without any luck. – momo Oct 29 '14 at 08:33
  • @CapitanCavernícola Updated the question with part of config file. – momo Oct 29 '14 at 08:35
  • Which EndPoints are failing? – Peter Kiss Oct 29 '14 at 08:59
  • @PeterKiss see updated service part – momo Oct 29 '14 at 09:11
  • Are you calling the endpoint that is failing as a SOAP service or a REST service? `basicHttpBinding` is a SOAP binding, and normally SOAP returns XML, not JSON, but based on the error it sounds like the service is returning JSON. – Tim Oct 29 '14 at 09:20
  • 1
    Maybe you can "comment" all the endpoints but 'ProductServiceAjaxSecureEndPoint', to be sure you're using it. – Morcilla de Arroz Oct 29 '14 at 09:24
  • I am calling the endpoint as ajax POST from a web and as a normal POST from a mobile app, we are sending JSON and expecting JSON. The server says it expects XML. The funny part is the same code runs fine on HTTP, this error only happens on HTTPS :S – momo Oct 29 '14 at 09:26

5 Answers5

9

WCF can have different endpoints for HTTP or HTTPs. I think this is the problem, so I will put it as an "answer" (I hope it helps you):

Your endpoint name="ProductServiceEndPoint" address="" it's exposed at your base address. OK

Your endpoint name="ProductServiceSecureEndPoint" address="ProductServiceSecure" bindingConfiguration="SecureBasicHttpBinding" it's exposed at base "base_address]/ProductServiceSecure".

So this endpoint:

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

It's incorrect, because the address may be "ProductServiceSecure"

Morcilla de Arroz
  • 2,104
  • 22
  • 29
  • It makes sense, I am accepting it hoping it will help someone else with this problem in the future. Saludos ;-) – momo Oct 31 '14 at 02:28
2

The basicHttpBinding can not work with JSON. Change the basicHttpBinding (SOAP) to webHttpBinding (REST) if you want to use JSON.

Peter Kiss
  • 9,309
  • 2
  • 23
  • 38
  • Then how would you explain that the same exact code works fine with JSON on HTTP? This problem only happens when doing the POST with HTTPS. I can't understand why – momo Oct 29 '14 at 09:30
  • 1
    I would say your are examining the wrong endpoint or the call to the sarvice isn't requesting json because the basicHttpBinding never supported json at all. – Peter Kiss Oct 29 '14 at 09:44
  • 1
    Same exact code can't be, I suppose you're setting the proxy anyway. For more testing: Could you try the place 'only' instead of '', and comment the endpoint that you're not using in HTTPS ? – Morcilla de Arroz Oct 29 '14 at 09:53
1

For this problem solution is that, In your request/response model there is some class who have not by default constructor which is parameterless.

Mukesh Methaniya
  • 752
  • 1
  • 5
  • 13
0

At the end our back-end developer changed the endpoint address field and routed it to specific paths (instead of address="") to test if it was working and it was. Apparently, according to what he said, the HTTP and HTTPS endpoints were trying to use the same address and that wasn't working. So he finally commented the HTTP endpoints and set the address for the HTTPS ones.

I don't know if that make much sense since I have no idea about WCF. To me, having some knowledge on Apache servers, it seems that you should be able to specify an endpoint and it shouldn't be based on/linked to the protocol used for connecting to it.

momo
  • 3,404
  • 6
  • 37
  • 66
0

In configfile add in service tag name="namespace.Service" then in endpoint tag

address="" behaviorConfiguration="web" binding="webHttpBinding"
     contract="namespace.IService"

and in IService interface

[WebInvoke(Method = "POST", UriTemplate = "functionname", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
Rahul Shukla
  • 646
  • 6
  • 19