1

我正在使用 webHttpBinding 为 json ajax 调用开发 WCF 服务。在我打开安全部分之前,该服务运行良好。这是我的 web.config。

      <serviceCredentials >
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="UserNamePasswordValidator, WebServices" />
      </serviceCredentials>
      <serviceAuthorization principalPermissionMode="Custom">
        <authorizationPolicies>
          <add policyType="AuthorizationPolicy, WebServices" />
        </authorizationPolicies>
      </serviceAuthorization>
      <!---->
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="WebHttpBehaviour">
      <enableWebScript />
      <webHttp automaticFormatSelectionEnabled="false" defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json" helpEnabled="true" />
    </behavior>
  </endpointBehaviors>
</behaviors>

这是我的javascript调用。

$.ajax({
       headers: {
                "Authorization": "Basic " + Base64.encode('John:Doe')
            },
            type: "POST",
            url: "https://localhost/StatusService.svc/CheckStatus",
            data: JSON.stringify({"companyName":"test"}),
            contentType: "text/json; charset=utf-8",
            dataType: "json",
            processdata: false,
            success: function (data) {
                alert('ok!');
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(textStatus + ' / ' + errorThrown);
            }
        });

我收到错误消息:执行 ajax 调用时出现对象错误。有什么我做错了吗?谢谢。

4

1 回答 1

3

找到以下解决方案。效果很好。 http://sameproblemmorecode.blogspot.com/2011/10/creating-secure-restfull-wcf-service.html

于 2012-11-16T16:14:27.207 回答