【问题标题】:ajax request giving access denied while calling wcf serviceajax 请求在调用 wcf 服务时拒绝访问
【发布时间】:2014-12-21 22:38:59
【问题描述】:

我创建了一个亚马逊 EC2 实例,并在 80 端口上托管了我的 .net Web 应用程序,在 1212 端口上托管了 WCF 服务。

在远程会话中,我可以在本地浏览应用程序和服务,并且可以进行 ajax 请求调用。

只有当我尝试在互联网上执行相同的功能时(不在同一个远程会话上),它在端口 1212 上对 wcf 服务进行 ajax 调用时才会出现拒绝访问错误。我添加了 $.support.cors = true;在提出请求时。

网络应用web.config:

<configuration>
    <system.web>
        <connectionStrings>
            <add name="ApplicationServices"   
                 connectionString="Server=somedbinstance.asdkfjlksd.us-west-2.rds.amazonaws.com;Initial Catalog=xed; user id=user ;password=pwd" 
                 providerName="System.Data.SqlClient" />
        </connectionStrings>
    </system.web>
    <system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="webEndpoint">
                    <webHttp defaultBodyStyle="Wrapped" 
                             defaultOutgoingResponseFormat="Xml" helpEnabled="true" />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <bindings>
            <webHttpBinding>
                <binding name="webHttpBinding" />
            </webHttpBinding>
        </bindings>
        <client>
            <endpoint name="BasicHttpBinding_ICustomerRequestService" 
                address="http://10.90.12.121:1212/myservice.svc" 
                binding="webHttpBinding" bindingConfiguration="webHttpBinding" 
                behaviorConfiguration="webEndpoint" 
                contract="CustomerRequestService.ICustomerRequestService" />
        </client>
        <serviceHostingEnvironment 
             aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
        <defaultDocument>
          <files>
            <add value="index.aspx" />
          </files>
        </defaultDocument>
    </system.webServer>
</configuration>

WCF 服务web.config:

<system.serviceModel>
    <services>
        <service name="iHandyService.CustomerRequestService">
            <endpoint 
                address="" 
                behaviorConfiguration="restfulBehavior" 
                binding="webHttpBinding" bindingConfiguration="" 
                contract="Interfac.ICustomerRequestService" />
               <host>
                   <baseAddresses>
                       <add baseAddress="http://10.90.12.121:1212/myservice.svc" />
                   </baseAddresses>
               </host>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
            <behavior name="restfulBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
   <httpProtocol>
       <customHeaders>
           <add name="Access-Control-Allow-Origin" value="*" />
           <add name="Access-Control-Allow-Headers" value="Content-Type" />
       </customHeaders>
   </httpProtocol>
   <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

Ajax 调用:

error 函数给出拒绝访问错误。

请指导我了解此错误以及如何解决它。

【问题讨论】:

    标签: asp.net ajax wcf amazon-ec2


    【解决方案1】:

    您需要将此端口添加到AWS控制台->EC2-->安全组-->入站规则-->端口。这个链接会很有帮助。您需要选择与您的实例对应的安全组,这在实例链接中也可见。

    LINK1 , LINK2

    还要确保您已将此端口添加到 Windows 防火墙入站规则。 - http://technet.microsoft.com/en-us/library/cc947789(v=ws.10).aspx

    注意:您可能需要配置 WCF 服务以支持 CORS,请点击此链接 - WCF REST Service Template 40(CS) Cross domain error,我已经回答了如何启用 CORS。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 2012-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      相关资源
      最近更新 更多