locked
System.TimeoutException in "Hello World" sample RRS feed

  • Question

  • Hello

    I'm newbie to WCF so i started by playing with "Hello World" sample 

    Everything works great except last step (Securing Communication Between the Client and Server) When i change binding to WSHttpBinding and run app (server then client), messages are sended ok, client ends but server hangs on HService.Close(); After a while, System.TimeoutException is thrown :

    System.TimeoutException was unhandled
      Message="Unable to claim lock within the given timeout."
      Source="System.ServiceModel"
      StackTrace:
           at System.ServiceModel.Channels.ThreadNeutralSemaphore.Enter(TimeSpan timeout)
           at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySessionChannel.TryReceiveRequest(TimeSpan timeout, IRequestContext& requestContext)
           at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySessionChannel.TryReceive(TimeSpan timeout, Message& message)
           at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySimplexSessionChannel.WaitForShutdown(TimeSpan timeout)
           at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecuritySimplexSessionChannel.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
           at System.ServiceModel.Channels.ChannelManagerBase.CloseChannels(TimeSpan timeout)
           at System.ServiceModel.Channels.SecurityChannelListener`1.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
           at System.ServiceModel.Channels.ChannelListenerBase.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.DelegatingChannelListener`1.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
           at System.ServiceModel.BindingListener.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
           at System.ServiceModel.BindingManager.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
           at System.ServiceModel.ServiceHostBase.OnClose(TimeSpan timeout)
           at System.ServiceModel.ServiceHost.OnClose(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
           at System.ServiceModel.Channels.CommunicationObject.Close()
           at HelloService.Server.Main(String[] args) in C:\Documents and Settings\Liwoj.MEDIARESEARCH\My Documents\Visual Studio 2005\Projects\IndigoTest\Server\Server.cs:line 21
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()

    Using VS.NET 2005 RTM, WinXP En SP2, WinFX January CTP

    Are there any prerequisities for using wsHttpBinding (for example WSE installed) ? I ques not .

    Thanx

    Friday, March 3, 2006 2:33 PM

Answers

  • WCF is no diferent from the rest of .NET:
    IDisposable has absolutely nothing to do with garbage collection. It is up to you to call it, and there is no magic that does it for you.

     

    Thanks,

    Juval Lowy IDesign Inc.

    Monday, March 6, 2006 1:56 AM

All replies

  •  

    in jan ctp,in some cases,wcf runtime didn't report error,it waits for some time and then we get timeout exception.

    please install feb ctp,it is billion times better than Jan ctp

    http://blogs.msdn.com/madhuponduru/archive/2006/02/22/537622.aspx

    I am thinking may be mis matching binding causing this problem,can you please make sure you changed binding in both client and server

    //when you are adding binding programmatically,we don't need config on server side

    My service code:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.ServiceModel;

     

    namespace HelloService
    {

        class Program
        {

            static void Main(string[] args)
            {

     

                Uri baseURI = new Uri("http://localhost/hello");

                ServiceHost HService = new

                ServiceHost(typeof(HelloService), baseURI);

                HService.AddServiceEndpoint(typeof(HelloService),

                                       new WSHttpBinding(), baseURI);

     

                HService.Open();

                Console.WriteLine("Service at your service.");

                Console.ReadKey();

                HService.Close();

     

            }

        }

     

        [ServiceContract]

        class HelloService
        {

            [OperationContract]

            string sayHi()
            {

                return ("Hi!");

     

            }

        }

    }

    client code:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel;
    using clientapp.localhost;


    namespace HelloClient
    {

        class Program
        {

            static void Main(string[] args)
            {

                HelloServiceProxy p = new HelloServiceProxy();

                Console.WriteLine(p.sayHi());
                Console.ReadKey();
            }

        }

    }

    client config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
              
                <wsHttpBinding>
                    <binding name="WSHttpBinding_HelloService" bypassProxyOnLocal="false"
                        transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                        <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                        <security mode="Message">
                            <transport clientCredentialType="None" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="Windows" negotiateServiceCredential="true"
                                establishSecurityContext="true" />
                        </security>
                    </binding>
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost/hello" binding="wsHttpBinding"
                    bindingConfiguration="WSHttpBinding_HelloService" contract="clientapp.localhost.HelloService"
                    name="WSHttpBinding_HelloService" />
            </client>
        </system.serviceModel>
    </configuration>

    MORE INFO;

    SDK smaples is best resource to learn more about wcf

    http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/WCF_samples/html/d6a47b3e-75c7-45c6-88ea-658868276669.asp

    we have wcf seminars here

    http://windowscommunication.net/default.aspx?tabindex=3&tabid=45

    -Thank you

    Madhu

     

    Friday, March 3, 2006 5:08 PM
  • I'm sure I'v changed both server and client - like I said - client succesfully called server and exception was thrown when closing ServiceHost.....
    But, I'l do what You advice - dowload and try Feb CTP :)
     
    Thanx
     
     
    Friday, March 3, 2006 7:11 PM
  • sorry,I thought you have problem with sending messages,anyway i am trying to repro your problem in Feb ctp

    please install Feb ctp,so you can play with recent bits

    -Thank you

    Madhu

    Friday, March 3, 2006 7:35 PM
  • //If you close the proxy after you are done with the call,everything will be ok(client side)

         HelloServiceProxy p = new HelloServiceProxy();

         Console.WriteLine(p.sayHi());
                p.Close();
           Console.ReadKey();

    //If service host thinks,it has any active client connections,it has problem closing the service host,I am not sure this bug or by design,we will try to debug it

    //Feb ctp giving better error message

    Unhandled Exception: System.TimeoutException: The service's security session did
     not receive a 'close' message from the client within the configured time.


       at System.ServiceModel.Security.SecuritySessionServerSettings.ServerSecurityS
    implexSessionChannel.OnClose(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
       at System.ServiceModel.Channels.ChannelManagerBase.CloseChannels(TimeSpan tim
    eout)
       at System.ServiceModel.Channels.SecurityChannelListener`1.OnClose(TimeSpan ti
    meout)
       at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
       at System.ServiceModel.Channels.ChannelListenerBase.OnClose(TimeSpan timeout)

       at System.ServiceModel.Channels.DelegatingChannelListener`1.OnClose(TimeSpan
    timeout)
       at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
       at System.ServiceModel.Dispatcher.ChannelDispatcher.OnClose(TimeSpan timeout)

       at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
       at System.ServiceModel.ServiceHostBase.OnClose(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Close()
       at HelloService.Program.Main(String[] args) in C:\Documents and Settings\madh

     

    -Thank you

    Madhu

     

    Friday, March 3, 2006 7:53 PM
  • I can confirm that calling Close on client proxy solved problem on JanCTP
     
    Thank you too :)
    Friday, March 3, 2006 9:35 PM
  • Another small comment :) because it twists my head  
    In first reply to "Why close proxy?" thread, Michele wrote this:
    "The proxy inherits ClientBase<T> which provides a Close() method to close the communication channel. It also implements IDisposable which will ultimately call Close() if you forget, but that relies on garbage collection which is nondeterministic. So, better if you close."
    I understand this. Proxy really inherits Dispose method from ClientBase<T> and by surrounding proxy creation with using statement, everything works fine without explicitly calling Close on it. So, Dispose method probably calls Close or do quite similar work as Close (confirmed by .net reflector)
     
    Its clear from my experiments that when proxy is not Closed or Disposed explicitly (by using(...) for example), Dispose method is not called.
    From what i know about IDisposable objects (thus object which allocate unmanaged resources which is true for ClientBase i guess), they should always have finalizer which calls Dispose() method... (NET Framework Resource Management )
     
    did i miss something ?
    thanx
    Saturday, March 4, 2006 10:55 AM
  • WCF is no diferent from the rest of .NET:
    IDisposable has absolutely nothing to do with garbage collection. It is up to you to call it, and there is no magic that does it for you.

     

    Thanks,

    Juval Lowy IDesign Inc.

    Monday, March 6, 2006 1:56 AM
  • Exactly ! So, where there are some (unmanaged) resources that must be disposed and call to Dispose (or Close) is not optional but necessary, class implementing IDisposable should have finalizer calling Dispose.....
    That was my point.
    I just dont know if this is the case for situation i described (call to ServiceHost.Close timeouted after not calling Close on client proxy) . Maybe this behaviour is "by design"....
     
    Thanx
    Monday, March 6, 2006 8:09 AM