Bit of background on my question…
I have a website and multiple console apps that access the same data layer (Linq-To-Sql) to set/get data. The console apps run across our network and they all update the central database via WCF services. The website is used to display the data captured by the apps data to the users.
My WCF services works when I’m returning simple types and when I’m returning lists of my custom objects BUT my service falls over with an ‘underlying connection was closed error’ whenever I try and return anything within an IEnumerable/IQueryable.
I thought it was possible to return IEnumerables/IQueryables over WCFs services ? Is is possible, or, am I just configuring my service wrong ? I’m using basicHttpBinding instead of wsHttpBinding but I’m still not 100% in what situation it is best to use the different types.
My set-up is like this :
public class CageService : ICageRepository
{
public IEnumerable<Cage> GetAll()
{
var dc = new DataContext();
return dc .GetAll();
}
}
[ServiceContract]
public interface ICageRepository : IRepository<Cage>
{
[OperationContract]
IEnumerable<Cage> GetAll();
}
Service Config :
<system.serviceModel>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="CageService" behaviorConfiguration="CageServiceTypeBehaviors" >
<host>
<baseAddresses>
<add baseAddress = "http://localhost/UHFWebsite/" />
</baseAddresses>
</host>
<!-- Add the following endpoint. -->
<!-- Note: your service must have an http base address to add this endpoint. -->
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<endpoint address ="" binding="basicHttpBinding" contract="Wavin.CageTracking.DataLayer.Interfaces.ICageRepository" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CageServiceTypeBehaviors" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Client config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICageRepository1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:2000/UHFServices/CageService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICageRepository1"
contract="CageRepositoryClient.ICageRepository" name="BasicHttpBinding_ICageRepository1" />
</client>
</system.serviceModel>
calling code looks like:
void method()
{
var client = new CageRepositoryClient();
CageListView.DataSource = client.GetAll();;
CageListView.DataBind();
}
You need to add the Cage class to the known types of your service in the implementation of your interface.