0
votes

I get a timeout exception whenever trying to connect to my selfhosted wcf.

This is config I have:

<configuration>
  <system.serviceModel>        
    <behaviors>
        <serviceBehaviors>
            <behavior name="MetaBehaviour">
                <serviceMetadata />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="MetaBehaviour" name="WcfStreaming.LargeDataService">
            <clear />
            <endpoint address="net.tcp://localhost/LargeData" binding="netTcpBinding"
                name="Tcp" contract="WcfStreaming.ILargeDataService" listenUriMode="Explicit" />
            <endpoint address="net.tcp://localhost/LargeData/mex" binding="mexTcpBinding"
                name="TcpMex" contract="IMetadataExchange" listenUriMode="Explicit" />
            <endpoint address="http://localhost/wcfstreaming" binding="basicHttpBinding"
                bindingConfiguration="" name="BasicHttp" contract="WcfStreaming.ILargeDataService" />
        </service>
     </services>
  </system.serviceModel>
</configuration>

And here is hosting code:

 host = new ServiceHost(typeof(WcfStreaming.LargeDataService),
           new Uri[] { HttpUri, TcpUri });

 host.Open();

 var factory = new ChannelFactory<WcfStreaming.ILargeDataService>(new NetTcpBinding(), new EndpointAddress(TcpUri)); //  Hnew NetTcpBinding(), new EndpointAddress(TcpUri));

 srvChannel = factory.CreateChannel();

 using (OpenFileDialog dlg = new OpenFileDialog())
 {
    if (dlg.ShowDialog() == DialogResult.OK)
    {
       Stream str = srvChannel.GetFile(dlg.FileName); //Exception here

       StreamReader sr = new StreamReader(str);
       string bf = sr.ReadToEnd();
       File.WriteAllText(@"C:\test", bf);
    }
 }

I get nasty:

This request operation sent to net.tcp://localhost/LargeData did not receive a reply within the configured timeout (00:01:00). The time allotted to this operation may have been a portion of a longer timeout. This may be because the service is still processing the operation or because the service was unable to send a reply message. Please consider increasing the operation timeout (by casting the channel/proxy to IContextChannel and setting the OperationTimeout property) and ensure that the service is able to connect to the client.

1
Try enabling tracing at the server, you'll likely get a better exception at the traces than at the client.carlosfigueira
Well, you seem to be sending around large amounts of data, and your naming leads to believe you might be wanting to use streaming, too.... maybe the timeout is just too short - have you tried increasing the timeouts to e.g. 3 minutes (instead of 1) ??marc_s
What I've noticed is that running under VS is fine: built-in wcf client is running on .../mex. So should I add mex endpoint manually to the servicehost?Nickolodeon
carlosfigueira, tracing? How to?Nickolodeon

1 Answers

2
votes

you can add wcf tracing by placing the following in your app.config file ( the project calling your wcf service, not the wcf service app.config file ). The trace is dumped out to c:\wcf.svclog

<system.diagnostics>
      <sources>
        <source name="System.ServiceModel"
                switchValue="Information, Warning, ActivityTracing, Error, Critical"
                propagateActivity="true">
          <listeners>
            <add name="traceListener"
                type="System.Diagnostics.XmlWriterTraceListener"
                initializeData= "c:\wcf.svclog" />
          </listeners>
        </source>
      </sources>
    </system.diagnostics>

Also if it is running under VS, but not outside of it, it means the servicehost you are creating doesnt match the service endpoint defined in your app.config file ( again the config file for the project calling the wcf, not the wcf's app.config file). OR the servicehost instantiation code never gets run.

It runs under VS becasue VS by default creates a WCF debugging host that loads your wcf service and exposes both the service and the MEX url. Sometimes this debugging aid keeps running if your application crashes. the process is wcfsvchost.exe.

"Mex" allows you to get the meta data on the service, so it is not needed for the final program.