4

我有一个托管在 .NET 3.5 Web 应用程序内的 IIS 6.0 中的 wcf 服务,它在 http 上运行良好,但是当我尝试实现 https/ssl 时,我收到一个 415 错误,并显示以下错误消息。我将 json 用于请求和响应。

“无法处理消息,因为内容类型 'application/json' 不是预期的类型 'application/soap+xml; charset=utf-8'。”

下面是我的客户端 jquery.ajax 调用、服务合同和 web.config。我在这里想念什么?

Jquery.ajax 调用:

    $.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服务合同:

<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)

网络配置:

 <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>
4

2 回答 2

1

我认为您的 web.config Tone 中需要一个带有 webHttpBinding 的端点。

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

请参阅在 WCF 服务中公开 webHttpBinding 端点

WCF 服务方法返回 json 或 soap

于 2012-12-01T13:30:12.630 回答
0

请在 Ajax 调用中指定以下内容

内容类型:“应用程序/json;字符集=utf-8”

于 2015-03-30T10:07:46.153 回答