4

I have a wcf service that is hosted in IIS 6.0 inside a .NET 3.5 web application and it is working fine over http, but when I try to implement https/ssl I get a 415 error back with the following error message. I am using json for both request and response.

"Cannot process the message because the content type 'application/json' was not the expected type 'application/soap+xml; charset=utf-8'."

Below is my client side jquery.ajax call, service contract and web.config. What am I missing here?

Jquery.ajax call:

    $.ajax({
    type: "POST",
        url: "DataShare.svc/GetProgramsByEventType",
        data: '{"eventTypeIds": "' + eventTypeId + '"}',
        contentType: "application/json",
        dataType: "json",
        async: false, //async needs to be false to work with programs dropdown
        success: function (data, status) {
            var programs = data.GetProgramsByEventTypeResult;
            var html = "";
            for (var i = 0; i < programs.length; i++) {
                html += "<li><a href='#'>" + programs[i].m_ProgramLongDesc + "<span class='value'>" + programs[i].m_ProgramID + "</span></a></li>"
            }
            $("#ddlProgramItems").html(html);
        },
        error: function (request, status, error) {
            alert("Error - Status: " + request.status + "\nStatusText: " + request.statusText + "\nResponseText: " + request.responseText);
     }
});

WCF service contract:

<ServiceContract()> _
Public Interface IDataShare
    <OperationContract()> _
    <WebInvoke(Method:="POST",
               BodyStyle:=WebMessageBodyStyle.Wrapped,
               RequestFormat:=WebMessageFormat.Json,
               ResponseFormat:=WebMessageFormat.Json)> _
    Function GetProgramsByEventType(eventTypeIds As String) As List(Of WF.DataContracts.Program.Program)

web.config:

 <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="EndpointBehavior">
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
    <wsHttpBinding>
      <binding name="TransportSecurity" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        <security mode="Transport">
          <transport clientCredentialType="None"  />
          <!--<message clientCredentialType="Certificate"  negotiateServiceCredential="true"/>-->
        </security>
      </binding>
    </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ServiceBehavior"
               name="DataShare">
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="IDataShare"
                  bindingConfiguration="TransportSecurity"
                  behaviorConfiguration="EndpointBehavior"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
Tone
  • 2,793
  • 6
  • 29
  • 42

2 Answers2

1

I think you need an endpoint with a webHttpBinding in your web.config Tone.

<endpoint address=""
              binding="webHttpBinding"
              contract="IDataShare"
              bindingConfiguration="TransportSecurity"
              behaviorConfiguration="EndpointBehavior"/>

See Expose webHttpBinding endpoint in a WCF service

and WCF service method to return json or soap

Community
  • 1
  • 1
Martin Dandanell
  • 831
  • 1
  • 7
  • 20
0

Please specify following in Ajax call

contentType: "application/json; charset=utf-8"

Raja Shahid
  • 153
  • 2
  • 8