none
WCF service is not returning data when invoked through another WCF service RRS feed

  • Question

  • Hi,

    I am trying to a composite WCF service that consumes 3 atomic services. I have successfully created two services which return data when I run them on WCF test client. But as soon I try to use/consume/invoke one of the  through another service, it fails. The service does not return data even though I pass the same value that I pass while testing it on WCF test client.

    I am using Entity Framework version 6 for DB operations and Unity IoC controls for  Injection (Unity.WCF v 1.6).

    I have correctly specified Contracts for Service, and Data. Find below the code snippet for my service and Web config.

    SERVICE:

     [ServiceContract]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
        public class store1Service
        {
            IGroceryStore storeRepository;
            public store1Service()
                : this(new GroceryStore())
            {
            }

            public store1Service(IGroceryStore StoreRepository)
            {
                storeRepository = StoreRepository;
            }

     [OperationContract]
            public List<GroceryStoreData> GetAllStores(string storeAddress, string city)
            {
                List<GroceryStoreData> items = storeRepository.GetStoreInfoList(storeAddress, city);
                if (items == null)
                {
                    items = new List<GroceryStoreData>();
                    items[0].Store_name = "No data found";
                    items[0].Location_City = "No data found";
                    items[0].Location_GeoLocation = "No data found";
                    items[0].Location_address = "No data found";
                    return items;
                }
                return items;
            }

    *************

    IMPLEMENTATION

    1.  public List<GroceryStoreData> GetStoreInfoList(string storeStreetAddress, string city)
              {
                  List<GroceryStoreData> storeData = new List<GroceryStoreData>();
                  try
                  {
                      if (!string.IsNullOrEmpty(city))
                      {
                          city = city.ToLower();
                      }
                      if (!string.IsNullOrEmpty(storeStreetAddress))
                      {
                          storeStreetAddress = storeStreetAddress.ToLower();
                      }
                      bool check = GroceryStoreDetail.Any(m => m.LocationDetail.address.ToLower().Contains(storeStreetAddress) || m.LocationDetail.city.ToLower() == city);
                      if (check == true)
                      {
                          List<GroceryStoreDetail> GroceryStoreDetails = new List<GroceryStoreDetail>();
                          GroceryStoreData data = new GroceryStoreData();
                             GroceryStoreDetails = GroceryStoreDetail.Where(m => m.LocationDetail.address.ToLower().Contains(storeStreetAddress) || m.LocationDetail.city.ToLower() == city).ToList();
                             foreach (GroceryStoreDetail item in GroceryStoreDetails)
                             {
                                 data.Store_name = item.store_name;
                                 data.Location_address = item.LocationDetail.address;
                                 data.Location_City = item.LocationDetail.city;
                                 data.Location_State = item.LocationDetail.state;
                                 data.Location_ZipCode = item.LocationDetail.zip_code;
                                 data.Location_GeoLocation = item.LocationDetail.GeoLocationDetail.geo_location;
                                 storeData.Add(data);
                             }
                      }
                      else
                      {
                          storeData = null;
                      }
                  }
                  catch (DbException ex)
                  {
                      ex.GetBaseException();
                  }
                  catch (Exception ex)
                  {
                      ex.GetBaseException();
                  }
                  return storeData;
              }



    ######################################################################

    WEBCONFIG

                 

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
      </configSections>
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5"/>
        <httpRuntime targetFramework="4.5"/>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
         <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https"/>
        </protocolMapping>

        <!-- <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> -->
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
          <serviceActivations>
            <add factory="store1API.WcfServiceFactory" relativeAddress="./store1Service.svc" service="store1API.Operation.store1Service"/>
          </serviceActivations>
        </serviceHostingEnvironment>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
      </system.webServer>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0"/>
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
      </entityFramework>
      <connectionStrings>
        <add name="storeDB1Entities" connectionString="metadata=res://*/Data.Model1.csdl|res://*/Data.Model1.ssdl|res://*/Data.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=storeDB1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>
      </connectionStrings>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0"/>
    </dependentAssembly>

          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0"/>

          <!--<dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
          </dependentAssembly>-->
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    ###########################################################

    DATA LAYER:

     [DataContract]
        public class GroceryStoreData
        {
            // Use a data contract as illustrated in the sample below to add composite types to service operations.
            //bool boolValue = true;
            //string stringValue = "Hello ";

            private int store_id = 0;
            private string store_name = string.Empty;
            private string storelocation_address = string.Empty;
            private string storelocation_city = string.Empty;
            private string storelocation_state = string.Empty;
            private int? storelocation_zipCode = 0;
            private string storelocation_GeoLocation = string.Empty;

            [DataMember]
            public int Store_id
            {
                get { return store_id; }
                set { store_id = value; }
            }

            [DataMember]
            public string Store_name
            {
                get { return store_name; }
                set { store_name = value; }
            }

            [DataMember]
            public string Location_address
            {
                get { return storelocation_address; }
                set { storelocation_address = value; }
            }

            [DataMember]
            public string Location_City
            {
                get { return storelocation_city; }
                set { storelocation_city = value; }
            }

            [DataMember]
            public string Location_State
            {
                get { return storelocation_state; }
                set { storelocation_state = value; }
            }

            [DataMember]
            public int? Location_ZipCode
            {
                get { return storelocation_zipCode; }
                set { storelocation_zipCode = value; }
            }

            [DataMember]
            public string Location_GeoLocation
            {
                get { return storelocation_GeoLocation; }
                set { storelocation_GeoLocation = value; }
            }

        }
    }

    Please reply if you find <g class="gr_ gr_335 gr-alert gr_gramm Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="335" id="335">mistake</g> or if you have any suggestions. I really need to fix this ASAP.

    Regards,

    Karan Sethi.



    Wednesday, February 25, 2015 9:18 AM

All replies

  • Hi,

    What's the error message when you call another service from the current service?

    Friday, February 27, 2015 3:34 PM
  • Hi Paul,

    I do not specifically get an error message. But as soon as I invoke the service the makes the intended service call and I get a failure message as I have handled the exceptions on the service being invoked.

    I can show you the service flow on a skype/team viewer screen sharing session, if you are comfortable.

    Regards,

    Karan

    Saturday, February 28, 2015 6:41 AM