0

I've been looking for a solution the whole day but couldn't find any information about the malfunction I have.

I'm connecting to a java webservice (wsdl ver. 1) with my c# application using a basichttpbinding. If connected, everything works fine absolutely stable and without any errors. But sometimes connecting is a big deal. My application hangs completely until it runs into a TimeoutException. Only after this happend I'm able to create as much connections as I want. But if I wait after a successful connection for something like 1 minute, the connections doesn't work - no matter how much I try. Only if I allow my application to run into a timeout it works again.

What's weird: If I wait for the timeoutException and continue my code by hitting F5 the connections work as if there's never been an exception and the expected data is beeing received?!

Strange thing is - no matter what timeout I set up: The timeout exception will always occur after round about 1 minutes but says, that the timeout exception was raised after the configured timeout value (e.g. 5s if I set I timeout of 5s).

Another thing is: If I can successfully connect, wireshark lists some TCP commands between client and server and then shows a lot of http commands. If the server connections hangs, there isn't even an tcp command that should have been sent from the client to the server. So it's understandable, that there's no response if there's no request.

For me it seems like my tcp socked is locked for some reason and will only work again, if the timeout occurs and "frees" some sockets?!

Why is there no code? Honestly: I have no idea where I should look for the problem. It's no question of the basichttpbinding and thus I suppose it would pretty mess up this post without any additional information given. Also it's a whole load of code :)

So If you have any hint on where I should look for the failure, please help me :)

UPDATE 1 Here's the code reduced to a minimum. First call is UpdateBinding, second call is Connect.

public class ClientSettings
{
    public System.ServiceModel.EndpointAddress Address { get; set; }

    public TimeSpan CloseTimeout { get; set; } = new TimeSpan(0, 0, 10);    
    public TimeSpan OpenTimeout { get; set; } = new TimeSpan(0, 0, 10);     
    public TimeSpan SendTimeout { get; set; } = new TimeSpan(0, 0, 5);     

    public void UpdateBinding() { 

        Binding = new System.ServiceModel.BasicHttpBinding();
        Address = new System.ServiceModel.EndpointAddress
        (
            "http://" + Physicals.IPAdress + ":" + Physicals.Port + Physicals.SubDir
        );

        Binding.Name = "SoapBinding";

        Binding.CloseTimeout = CloseTimeout;
        Binding.OpenTimeout = OpenTimeout;
        Binding.SendTimeout = SendTimeout;

        Binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Mtom;
        Binding.AllowCookies = false;
        Binding.BypassProxyOnLocal = false;
        Binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
        Binding.MaxBufferSize = Int32.MaxValue;
        Binding.MaxBufferPoolSize = Int16.MaxValue;
        Binding.MaxReceivedMessageSize = Int32.MaxValue;
        Binding.TextEncoding = System.Text.Encoding.UTF8;
        Binding.TransferMode = System.ServiceModel.TransferMode.Buffered;
        Binding.UseDefaultWebProxy = true;

        System.Xml.XmlDictionaryReaderQuotas _readerquotas = new System.Xml.XmlDictionaryReaderQuotas();

        _readerquotas.MaxDepth = Int32.MaxValue;
        _readerquotas.MaxStringContentLength = Int32.MaxValue;
        _readerquotas.MaxArrayLength = Int32.MaxValue;
        _readerquotas.MaxBytesPerRead = Int32.MaxValue;
        _readerquotas.MaxNameTableCharCount = Int32.MaxValue;

        Binding.ReaderQuotas = _readerquotas;

        Binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.None;
        Binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;
        Binding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None;
        Binding.Security.Transport.Realm = "";

        Binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName;
        Binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

        bindingIsValid = true;
    }
}

public class ClientObject : ClientSettings, IDisposable
{
    public ImageServerClient Client { get; set; }
    public Generic.OMS4SystemInfo SystemInfo { get; set; }

    public System.ServiceModel.CommunicationState EndPointCommunicationState
    {
        get
        {
            return Client.State;
        }
    }

    public bool Connect()
    {
        if (bindingIsValid == false)
            return false;

        Client = new ImageServerClient(Binding, Address);

        getSystemInfo();

        return true;
    }

    public void Disconnect()
    {
        Client.Close();
    }

    public void Dispose()
    {
        this.Disconnect();
    }

    private void getSystemInfo()
    {
        systemInfo sInfo = new systemInfo();
        sInfo = this.Client.getSystemInfo();

        Generic.SystemInfo buffer = new Generic.SystemInfo();

        buffer.BuildDate = sInfo.buildDate;
        buffer.JavaRuntimeVersion = sInfo.javaRuntimeVersion;
        buffer.SoftwareVersion = sInfo.softwareVersion;
        buffer.SystemID = sInfo.systemID;

        this.SystemInfo = buffer;
    }
}

The TimeoutException is raised in the line

sInfo = this.Client.getSystemInfo();

UPDATE 2 I've done a lot of testing. It is def. no question of the server. It is also no question of the network hardware. I've changed everything but the problem persits.

No one an idea?

Update 3 Here's the complete error code and stack trace (sorry if my translation lacks some quality :)

Exception:
{"A timeout error occured after 00:00:15 while trying to send over the request channel. Increase the timeout limit of the \"Request\" invokation of increase the timeout limit for your binding. The timeout for this operation was possibly part of a longer timeout.}

Inner Exception:

{"The http-request at \"http://10.80.30.200:50000/SomeDataServer\" has exceeded the timeout limit of 00:00:00. The timeout for this operation was possibly part of a longer timeout.}

Server stack trace: 
    bei System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
    bei System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
    bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
    bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
    bei System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
    bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    bei SomeService.SomeDataServiceReference.ImageServer.getSystemInfo(getSystemInfo request)
    bei SomeService.SomeDataServiceReference.ImageServerClient.SomeService.SomeDataServiceReference.ImageServer.getSystemInfo(getSystemInfo request) in C:\Users\userx\Documents\Visual Studio 2015\Projects\Some Interface Stand 05.11.2015\Common\SomeService\Service References\SomeDataServiceReference\Reference.cs:Zeile 1019.
    bei SomeService.SomeDataServiceReference.ImageServerClient.getSystemInfo() in C:\Users\userx\Documents\Visual Studio 2015\Projects\Some Interface Stand 05.11.2015\Common\SomeService\Service References\SomeDataServiceReference\Reference.cs:Zeile 1024.
    bei Driver.ClientObject.getSystemInfo() in C:\Users\userx\Documents\Visual Studio 2015\Projects\Spielwiese\Spielwiese\Interface neu.cs:Zeile 175.
    bei Driver.ClientObject.Connect() in C:\Users\userx\Documents\Visual Studio 2015\Projects\Spielwiese\Spielwiese\Interface neu.cs:Zeile 150.
    bei Spielwiese.OMS4DriverWrapper.Worker_DoWork(Object sender, DoWorkEventArgs e) in C:\Users\userx\Documents\Visual Studio 2015\Projects\Spielwiese\Spielwiese\Wrapper.cs:Zeile 88.
    bei System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
    bei System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
AllDayPiano
  • 414
  • 1
  • 4
  • 20
  • can you show your server and client side config and the code of the ServiceContract you are testing? you can remove your business logic. – Glenn Ferrie Feb 02 '16 at 14:20
  • Unfortunatly I cannot post the server code because this I don't have the source. I'll try to clean up my client code a little and post it as update. – AllDayPiano Feb 02 '16 at 14:22
  • You should at the very least give us the full exception AND stacktrace. – Aron Feb 04 '16 at 08:49
  • Are `ClientObject`s being used inside `using` blocks, because if not, then you absolutely are leaking TCP sockets. – Aron Feb 04 '16 at 08:52
  • I updated the question. What do you mean about "leaking tcp sockets"? – AllDayPiano Feb 04 '16 at 09:27
  • Ohhh I think I got it. Do you mean, that each time I'm invokating a web service function, a new socket is beeing opened and locked? – AllDayPiano Feb 04 '16 at 09:37
  • @AllDayPiano something like that. Each HTTP connection needs a TCP Socket. Since HTTP v1.1 (1990), HTTP clients keep the socket open between HTTP requests (the feature is called HTTP keep-alive). Of course that takes up a resource (a TCP port), until the keep-alive timeout. There are two solutions, use the same HttpClient each time (to reuse the Socket, or you close the socket each time after you use it. – Aron Feb 05 '16 at 01:33
  • @Aron: What's weird about it: I'm not closing the client connection. I keep it alive in a static class where only one instance is created and reused the whole project lifetime. – AllDayPiano Feb 05 '16 at 06:35
  • Then that isn't the problem. But it sounds like it is a socket issue. – Aron Feb 05 '16 at 06:44
  • Another problem is that this timeout issue also appears, if i have rebooted the computer and do the first connection attempt. – AllDayPiano Feb 05 '16 at 08:56
  • https://stackoverflow.com/a/7898696/1203182 this might help – spy Oct 05 '19 at 21:37

0 Answers0