0

I have created an amazon EC2 instance and hosted my .net web application on port 80 and WCF service on port 1212 port.

Locally on the remote session I am able to browse both application and service and able to make ajax request calls.

Only when I try doing same functionality over the internet(not on same remote session) which makes ajax call to wcf service on port 1212 ``gives access denied error. I have added $.support.cors = true; while making request.

Web application 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 Service 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 call:

enter image description here

error function gives access denied error.

Please guide me on this error and how to resolve it.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user12345
  • 261
  • 3
  • 14

1 Answers1

0

You need to add this port to AWS console->EC2-->Security group-->Inbound rules-->Port. This link will be helpful. You need to select security group corresponding to your instance, and this is also visible in instances link.

LINK1 , LINK2

Also make sure, you have added this port to windows firewall inbound rule. - http://technet.microsoft.com/en-us/library/cc947789(v=ws.10).aspx

Note: You might need to configure WCF service to be CORS ready, follow this link - WCF REST Service Template 40(CS) Cross domain error, i have answered there how to make it CORS enabled.

Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48