2014-10-26 71 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啓用。

相關問題