1

I'm having a problem with my WCF Service, the methods itself collect the right data and return the correct datatypes however I always get the same error regardless of which bindingtype I use for my endpoints. I've tried TCP, HTTP and NamedPipe. The general error at the top is the following:

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

The one posted is from the HTTP binding.

 An error occurred while receiving the HTTP response to http://localhost:8732/ClubService/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IAndereBoekenService.BoekBeschikbaar(String isbn)
   at AndereBoekenServiceClient.BoekBeschikbaar(String isbn)

Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

Inner Exception:
An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.serviceModel>
    <services>
      <service name="ClubServiceLibrary.ClubService">
        <host>
          <baseAddresses>
            <add baseAddress="net.pipe://localhost/ClubService" />
            <add baseAddress ="net.tcp://localhost/ClubService" />
            <add baseAddress="http://localhost:8732/ClubService/" />
          </baseAddresses>
        </host>
        <endpoint name ="namedPipeClub"
                  binding="netNamedPipeBinding"
                  contract="ClubServiceLibrary.IClubServiceLibrary" />
        <endpoint name="namedPipeClubMEX"
                  address="mex"
                  binding="mexNamedPipeBinding"
                  contract="IMetadataExchange" />
        <endpoint name ="tcpClub"
                  binding="netTcpBinding"
                  contract="ClubServiceLibrary.IClubServiceLibrary" />
        <endpoint name="tcpClubMEX"
                  address="mex"
                  binding="mexTcpBinding"
                  contract="IMetadataExchange" />
        <endpoint binding="wsHttpBinding"
                  name="httpClub"
                  contract="ClubServiceLibrary.IClubServiceLibrary" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  name="httpClubMEX"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

I'm getting my data out of a dictionary which is filled up with dummy data in another class called "DummyData", this does get filled with data.

 private static Dictionary<int, Club> clubsValue;

 public static Dictionary<int, Club> Clubs
        {
            get { return clubsValue; }
        }

In my ClubService class I do the following:

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class ClubService : IClubService
    {
        public List<Club> GetClubByName(string search)
        {
            var searchToLower = search.ToLower();

            List<Club> test = DummyData.Clubs.Values.Where(b => b.Titel.ToLower().Contains(searchToLower)).ToList();

            return test;
        }
    }

My IClubInterface looks like this:

[ServiceContract(Namespace = "http://club.com/clubservice")]
interface IClubService
{
    [OperationContract]
    List<Club> GetClubByName(string search);
}

So when debugging all the data is in the list and I return the correct list.. however every single time I get this error messages and I have no idea how to resolve this.

1 Answers1

4

If I had to hazard a guess, I'd say it'll be something like an exception being thrown when serializing or deserializing your data upon return. The easiest way to track down this & most other WCF errors is to enable the WCF Log file and take a look at what it's generating with the WCF Log File viewer :

Add the following section to your application config file and then make sure the folder it is writing trace to exists (c:\temp\WCFLogs in the example below). You should start to see a ServerWCFTraces.svclog file be created - it might say 0 bytes in length until you stop your service or it decides to flush to disk.

Once you have reproduced your failure case, open up the log file on a machine with Visual Studio on (or download the viewer from here : SvcTraceViewer from MSDN.)

There's some instructions to use the tool on that MSDN link, but effectively you look for the errors (highlighted in red) in the activity pane (left), then zero in on the action which failed (top right pane) and in the details section (bottom right pane), there will be a description of the inner exception which is being thrown, which almost always tells you what the exception which is being thrown is and give you more information about how to resolve it.

<system.diagnostics>
  <sources>
     <source propagateActivity="true" name="System.ServiceModel" switchValue="Information, ActivityTracing">
        <listeners>
           <add name="ServiceModelMessageLoggingListener">
              <filter type="" />
           </add>
        </listeners>
     </source>
     <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
           <add name="ServiceModelMessageLoggingListener">
              <filter type="" />
           </add>
        </listeners>
     </source>
  </sources>
  <sharedListeners>
     <add initializeData="C:\temp\WCFLogs\ServerWCFTraces.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
     </add>
  </sharedListeners>
</system.diagnostics>
mcr
  • 762
  • 5
  • 19
  • 1
    Thanks to your help I found the correct exception to figure out the issue. The solution to this particular problem for me could be found here: http://stackoverflow.com/questions/18392402/circular-references-preventing-serialization-of-object-graph –  Mar 16 '15 at 21:08