2014-10-26 95 views
0

我创建了一个amazon EC2实例,并在端口80上托管了我的.net Web应用程序,并在端口1212端口上托管了WCF服务。ajax请求在调用wcf服务时拒绝访问

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

只有当我尝试通过互联网(不在相同的远程会话)上做相同的功能,这使得在端口1212上的ajax调用wcf服务时``会导致拒绝访问错误。我添加了$ .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> 

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调用:

enter image description here

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

请指导我解决这个错误以及如何解决它。

回答

0

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

LINK1LINK2

另外,还要确保你已经加入此端口的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启用。