none
WCF REST Service hosted in IIS 7 returns both XML and JSON response when accessed using localhost, but returns empty response when called remotely using hostname/IP RRS feed

  • Question

  • I've a peculiar problem here. I've hosted my WCF Rest service in a remote system in IIS 7.

    I'm able to receive a response from the service (either XML or JSON) when I call the service in the remote system itself using localhost

    http://localhost:12827/HighONDealsService/GetDeals/43.1656/-77.6114


    Sample response

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <ArrayOfDealObject xmlns="http://schemas.datacontract.org/2004/07/HighONDealsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <DealObject>
    <Address>1196 Brooks Ave NY 14624</Address>
    <Category>Airport</Category>
    <City>Rochester</City>
    <Deals>Enjoy your stay with complimentary spa sessions</Deals>
    <Latitude>43.130763</Latitude>
    <Longitude>-77.668665</Longitude>
    <SearchResult>Fairfield Inn Rochester Airport</SearchResult>
    </DealObject>
    <DealObject>
    <Address>1555 Mt Hope Ave Rochester NY 14620</Address>
    <Category>Bars</Category>
    <City>Rochester</City>
    <Deals>Happy hours all this month</Deals>
    <Latitude>43.119709</Latitude>
    <Longitude>-77.619911</Longitude>
    <SearchResult>Sheridan's Pub</SearchResult>
    </DealObject>
    <DealObject>
    <Address>62 University Ave Rochester NY 14605</Address>
    <Category>Bars</Category>
    <City>Rochester</City>
    <Deals>
    Stay late and get drunk - free drinks on the house after 10pm
    </Deals>
    <Latitude>43.160850</Latitude>
    <Longitude>-77.601294</Longitude>
    <SearchResult>Tavern 58 At Gibbs</SearchResult>
    </DealObject>


    But as soon as I try to access the service using

    http://155.98.38.135:12827/HighONDealsService/GetDeals/43.1656/-77.6114,

    I get a blank response even in the remote system.

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <ArrayOfDealObject xmlns="http://schemas.datacontract.org/2004/07/HighONDealsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>

    This is my ServiceContract and DataContract

    [ServiceContract]
        public interface IHighONDealsService
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="userLat"></param>
            /// <param name="userLong"></param>
            /// <returns></returns>
            [OperationContract]
            [WebGet(UriTemplate = "GetDeals/{userLat}/{userLong}", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml)]
            List<DealObject> GetDeals(string userLat, string userLong);        
        }
    
        /// <summary>
        /// 
        /// </summary>
        [DataContract(IsReference = false)]
        public class DealObject
        {
            [DataMember]
            public string City;
    
            [DataMember]
            public string Category;
    
            [DataMember]
            public string SearchResult;
    
            [DataMember]
            public decimal Latitude;
    
            [DataMember]
            public decimal Longitude;
    
            [DataMember]
            public string Deals;
    
            [DataMember]
            public string Address;
        }


    My web.config looks like

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      
      <system.web>
        <compilation debug="true" targetFramework="4.5">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
        <pages controlRenderingCompatibilityVersion="4.0" />
      </system.web>
      
      <system.serviceModel>
        <services>
          <service name="HighONDealsService.HighONDealsService"
                    behaviorConfiguration="RESTBehavior">
            <endpoint address=""
                      binding="webHttpBinding"
                      contract="HighONDealsService.IHighONDealsService"
                      behaviorConfiguration="MyEndpointBehavior"/>
          </service>
        </services>
        
        <behaviors>
          <serviceBehaviors>
            <behavior name="RESTBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
          
          <endpointBehaviors>
            <behavior name="MyEndpointBehavior">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>
    
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
      </system.serviceModel>
      
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="UrlRoutingModule"
               type="System.Web.Routing.UrlRoutingModule, 
              System.Web.Routing, Version=4.0.0.0, 
              Culture=neutral, 
              PublicKeyToken=31BF3856AD364E35" />
    
        </modules>
        <handlers>
          <add name="UrlRoutingHandler"
             preCondition="integratedMode"
             verb="*" path="UrlRouting.axd"
             type="System.Web.HttpForbiddenHandler, 
             System.Web, Version=4.0.0.0, Culture=neutral, 
             PublicKeyToken=b03f5f7f11d50a3a" />
        </handlers>
        <directoryBrowse enabled="true" />
      </system.webServer>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
      
      <connectionStrings>
        <add name="DataContext" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PC535\SQLEXPRESS;initial catalog=CSharpTeamProject;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    </configuration>

    The service is binded to a specific port and the port has incoming and outbound rules set to no blocking.
    The container directory also has full read and execute permissions for Network Service and IIS_IUSRS.

    The Website in IIS only has Anonymous and Basic authentication enabled.

    Where am I going wrong?


    Saturday, November 30, 2013 3:46 AM

Answers

  • Seems the problem is with Windows Authentication for Entity Framework connectivity to the backend.
    • Marked as answer by Aurodeep Ghosh Saturday, November 30, 2013 10:24 PM
    Saturday, November 30, 2013 6:51 PM
  • You can't be using Windows Authentication on the backend if using Anonymous and Basic authentication on IIS. You have to use a generic user-id and psw  that has been established on the database, which would be used in the connections string that EF uses to login to the database.
    • Marked as answer by Aurodeep Ghosh Saturday, November 30, 2013 10:26 PM
    Saturday, November 30, 2013 7:36 PM

All replies

  • Seems the problem is with Windows Authentication for Entity Framework connectivity to the backend.
    • Marked as answer by Aurodeep Ghosh Saturday, November 30, 2013 10:24 PM
    Saturday, November 30, 2013 6:51 PM
  • You can't be using Windows Authentication on the backend if using Anonymous and Basic authentication on IIS. You have to use a generic user-id and psw  that has been established on the database, which would be used in the connections string that EF uses to login to the database.
    • Marked as answer by Aurodeep Ghosh Saturday, November 30, 2013 10:26 PM
    Saturday, November 30, 2013 7:36 PM
  • You can't be using Windows Authentication on the backend if using Anonymous and Basic authentication on IIS. You have to use a generic user-id and psw  that has been established on the database, which would be used in the connections string that EF uses to login to the database.
    Thanks Arnold :) I went through the same resolution and got my service running . Thanks anyways

    Saturday, November 30, 2013 10:26 PM