被拒绝访问财产"申请"在WCF restful服务中

本文关键字:quot restful 服务 WCF 拒绝访问 申请 财产 | 更新日期: 2023-09-27 18:14:53

在我的解决方案文件中,我添加了两个项目,一个是WCFService应用程序,另一个是空MVC应用程序。

在WCFService

public interface IProductService
    {
         [OperationContract]
         [WebInvoke(Method = "GET", UriTemplate = "/ProductName/{productID}",
            BodyStyle = WebMessageBodyStyle.Bare, 
            RequestFormat = WebMessageFormat.Json, 
            ResponseFormat = WebMessageFormat.Json)]
         string GetProductName(string productID);
     }

和WCF配置文件如下

<system.serviceModel>
    <services>
      <service behaviorConfiguration="Default"
               name="RESTFulWCFService.ProductService">
        <endpoint address="" behaviorConfiguration="webBehavior"
                  binding="webHttpBinding" contract="RESTFulWCFService.IProductService"></endpoint>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"></endpoint>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>        
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="*" />
        <add name="Access-Control-Allow-Headers" value="*" />
      </customHeaders>
    </httpProtocol>
    <directoryBrowse enabled="true"/>
  </system.webServer>

现在,当我调用我的WCF使用jquery然后在浏览器控制台,我得到这个错误。

**Error: Permission denied to access property "apply"**

Jquery代码

<script>
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "http://localhost:55827/ProductService.svc/ProductName/2",
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            success: function (result) {
                debugger;
                alert(result.d);
                console.log(result);
            },
            error: function (result) {
                debugger;
                alert('no');
            }
        });
    });
</script>

被拒绝访问财产"申请"在WCF restful服务中

请将属性添加到实现您的服务的类IProductService

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]