2015-09-29 100 views
0

在我的解决方案文件中,我添加了两个项目,一个是WCFService应用程序和其他空的MVC应用程序。权限被拒绝在WCF Restfull服务中访问属性“apply”

在WCFService中。

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

,并为后续

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

现在,当我使用jQuery那么在浏览器控制台我得到这个错误打电话给我的WCF WCF的配置文件。

**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> 
+0

你为什么不以你的MVC项目中添加服务引用类的? –

+0

这是WCF Restfull服务,那么为什么我需要在我的Web中使用WCF引用,何时可以使用Ajax调用它。 –

回答

0

请添加属性到谁正在实施服务IProductService

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
+0

感谢它的工作。但还有另一种解决方法。在ajax请求中添加'crossDomain:true,'。它也将起作用 –

+0

好的如果它完全填满了你的请求,那么标记并关闭这个问题,这对其他指导者和观察者会有帮助。 –

相关问题