通过另一个WCF服务调用时,WCF服务不返回数据

时间:2015-02-28 23:33:16

标签: c# web-services wcf visual-studio-2013 unity-container

我正在尝试使用3个原子服务的复合WCF服务。我已经成功创建了两个服务,当我在WCF测试客户端上运行它们时返回数据。但是,一旦我尝试使用/ consume /调用其中一个通过另一个服务,它就会失败。即使我在WCF测试客户端上测试它时传递了相同的值,该服务也不会返回数据。

我使用Entity Framework版本6进行数据库操作,使用Unity IoC控件进行注入(Unity.WCF v 1.6)。

我已正确指定服务合同和数据。在下面找到我的服务和Web配置的代码段。

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

 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>

0 个答案:

没有答案