0

So my question is much like this one: WCF service: Returning custom objects, however, despite the solutions in that question I see nothing working.

Yesterday I proposed a question related to this one, but I've come closer, if not identified the potential source of my issue.

I don't believe it is problem with the size of the data that I am working with. I can send this data to the server, but I am having a problem with retrieving it. I'm returning an object called ProjectDetails over WCF. However, I run into an issue with receiving it from the service to the client.

Is there a setting that I am missing or is there a way I configured my class for WCF incorrectly?

Here is my ProjectDetails code:

[DataContract]
public class ProjectDetails 
{
    [DataMember]
    public int projectId { get; set; }
    [DataMember]
    public string name { get; set; }
    [DataMember]
    public int calYearId { get; set; }
    [DataMember]
    public string projectState { get; set; }
    [DataMember]
    public string reportTitle { get; set; }
    [DataMember]
    public int plantId { get; set; }
    [DataMember]
    public string holdNumber { get; set; }
    [DataMember]
    public string holdDescription { get; set; }
    [DataMember]
    public string remarks { get; set; }
    [DataMember]
    public string adminComments {get; set; }
    [DataMember]
    public int companyId { get; set; }
    [DataMember]
    public int customerId { get; set; }
    [DataMember]
    public string folderNumber { get;  set; }
    [DataMember]
    public int invoicedInFull { get; set; }
    [DataMember]
    public int approved { get; set; }
}

Here is how the it is defined in my Service Contract:

[ServiceContract]
public interface IProjectService
{
    [OperationContract]
    ProjectDetails GetProjectDetails(int selected_id);
}

I have regenerated my proxy with svcutil.exe and updated my service reference. However, every time I call the GetProjectDetails method my code fails. I get:

The underlying connection was closed: An unexpected error occurred on a receive.

Please, if anyone can help, I would be so grateful.

Update

Client side config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IProjectService" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://192.168.0.99:9000/ProjectService/ProjectService"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IProjectService"
                contract="IProjectService" name="BasicHttpBinding_IProjectService" />
        </client>
     </system.serviceModel>
</configuration>

Client side config:

<?xml version="1.0"?>
<configuration> 
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ProjectBaseWCFServiceLib.Service1Behavior" name="ProjectBaseWCFServiceLib.ProjectService">
        <endpoint address="" binding="basicHttpBinding" contract="ProjectBaseWCFServiceLib.IProjectService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/ProjectBaseWCFServiceLib/Service1/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ProjectBaseWCFServiceLib.Service1Behavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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 -->
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Client side code:

        Console.WriteLine("Testing................");
        ProjectBaseWCFServiceLib.ProjectDetails details = client.GetProjectDetails(1);

        Console.WriteLine(details.adminComments);
        Console.WriteLine(details.approved);
        Console.WriteLine(details.calYearId);
        Console.WriteLine(details.companyId);
        Console.WriteLine(details.folderNumber);
        Console.WriteLine(details.holdDescription);
        Console.WriteLine(details.holdNumber);
        Console.WriteLine(details.invoicedInFull);
        Console.WriteLine(details.name);
        Console.WriteLine(details.plantId);
        Console.WriteLine(details.projectId);
        Console.WriteLine(details.projectState);
        Console.WriteLine(details.remarks);
        Console.WriteLine(details.reportTitle);
Community
  • 1
  • 1
Derek W
  • 9,708
  • 5
  • 58
  • 67
  • Any inner exceptions? – wgraham May 23 '13 at 13:26
  • Yes, but they are all so generic. I get `Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host` as well. – Derek W May 23 '13 at 13:29
  • are you using linq or transaction scopes in your code? – guiomie May 23 '13 at 13:38
  • Please do enable Tracing (http://msdn.microsoft.com/en-us/library/ms733025.aspx) on your WCF service and inspect the trace log to know more details on why the error is being thrown. – Rajesh May 23 '13 at 13:38
  • getting the full stacktrace would also help – guiomie May 23 '13 at 13:42
  • I have tracing enabled. – Derek W May 23 '13 at 13:56
  • to suggest something we need to see servicemodel configuration for both client and server and code on client side – paramosh May 23 '13 at 15:01
  • Added the servicemodel config for both client and server and the client side code. – Derek W May 23 '13 at 15:29
  • it looks you are using different addresses on client and on server side. Why? – paramosh May 23 '13 at 15:57
  • does anything else work for you ? i dont think the problem is with data contract. the problem is on your settings, what are the endpoints both on client and server ? – ilansch May 23 '13 at 21:56
  • the Data structure does not look heavy unless you have too many records to return...how many records r u planning on returning....u can set a message size configuration in app.config...make a small data set and try return it to a console app and see wat happens... – SutharMonil May 24 '13 at 10:53
  • Message size config looks like: – SutharMonil May 24 '13 at 10:54
  • I see that in your services section the port on which your service is running is 8732 and in the client section your endpoint address points to port 9000. Make sure that you are connecting to the correct service and its up and running – Rajesh May 24 '13 at 16:06

2 Answers2

0

If you are going to host your service in IIS this service configuration will work for you

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ProjectBaseWCFServiceLib.Service1Behavior" name="ProjectBaseWCFServiceLib.ProjectService">
        <endpoint address="" binding="basicHttpBinding" contract="ProjectBaseWCFServiceLib.IProjectService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ProjectBaseWCFServiceLib.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

If you are going to have it self hosted, add proper base address. But anyway you should be sure that ServiceConfig is in web/app.config file of the application which hosts the service. It's not enough and not necessary to update config of your Lib project.

paramosh
  • 2,258
  • 1
  • 15
  • 23
0

It ended up being that the server side code was throwing an exception due to the occurrence of:

int.Parse("0");

This was the sole cause of the problem. When I looked through the trace logs and saw the StringFormatException it made no sense to me, but when I stepped through the code it became glaringly obvious of where/ when/ why this exception was being thrown.

A great lesson was learned here - debugging a Client-Server program is much different than just a classic standalone program.

Derek W
  • 9,708
  • 5
  • 58
  • 67