Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 调用wcf服务时拒绝提供访问权限的ajax请求_Asp.net_Ajax_Wcf_Amazon Ec2 - Fatal编程技术网

Asp.net 调用wcf服务时拒绝提供访问权限的ajax请求

Asp.net 调用wcf服务时拒绝提供访问权限的ajax请求,asp.net,ajax,wcf,amazon-ec2,Asp.net,Ajax,Wcf,Amazon Ec2,我已经创建了一个AmazonEC2实例,并在端口80上托管了我的.NETWeb应用程序,在端口1212上托管了WCF服务 在远程会话的本地,我能够浏览应用程序和服务,并能够进行ajax请求调用 只有当我尝试在internet上(而不是在同一远程会话上)执行相同的功能时,在端口1212``上对wcf服务进行ajax调用时,才会出现拒绝访问错误。我添加了$.support.cors=true;在提出请求时 Web应用程序Web.config: <configuration> &l

我已经创建了一个AmazonEC2实例,并在端口80上托管了我的.NETWeb应用程序,在端口1212上托管了WCF服务

在远程会话的本地,我能够浏览应用程序和服务,并能够进行ajax请求调用

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

Web应用程序
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>
<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调用:

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


请指导我如何解决此错误。

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

,

另外,请确保已将此端口添加到windows防火墙入站规则中。-

注意:您可能需要将WCF服务配置为CORS就绪,请点击此链接-,我已经回答了如何使其启用CORS