我創建了一個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調用:
誤差函數給出拒絕訪問錯誤。
請指導我解決這個錯誤以及如何解決它。