WCF连接挂起 - 连接限制?

时间:2016-02-02 14:18:18

标签: c# wcf sockets tcp

我一直在寻找解决方案,但找不到有关我所遇到的故障的任何信息。

我正在使用basichttpbinding与我的c#应用程序连接到java webservice(wsdl ver.1)。如果连接,一切工作正常绝对稳定,没有任何错误。但有时连接是一件大事。我的应用程序完全挂起,直到它遇到TimeoutException。只有在这发生之后,我才能创建尽可能多的连接。但是如果我在成功连接1分钟之后等待,那么无论我尝试多少,连接都无法正常工作。只有当我允许我的应用程序进入超时时它才会再次运行。

有什么奇怪的:如果我等待timeoutException并通过点击F5继续我的代码,那么连接的工作就好像从来没有出现异常并且预期的数据被收到了?!

奇怪的是 - 无论我设置了什么超时:超过1分钟后超时异常将始终但是说,在配置的超时值之后引发了超时异常(例如5s)如果我设置超时为5秒)。

另一件事是:如果我能成功连接,wireshark会在客户端和服务器之间列出一些TCP命令,然后会显示很多http命令。如果服务器连接挂起,则甚至没有应该从客户端发送到服务器的tcp命令。所以这是可以理解的,如果没有请求就没有回应。

对我来说,似乎我的tcp socked由于某种原因被锁定并且只会再次工作,如果发生超时并“释放”一些套接字?!

为什么没有代码?老实说:我不知道应该在哪里寻找问题。这不是basichttpbinding的问题,因此我认为如果没有给出任何额外的信息,这个帖子会非常混乱。这也是一大堆代码:)

所以,如果您有任何提示我应该查找失败的地方,请帮助我:)

更新1 这里的代码减少到最低限度。第一个电话是 UpdateBinding ,第二个电话是连接

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;
    }
}

在行

中引发了TimeoutException
sInfo = this.Client.getSystemInfo();

更新2 我做了很多测试。这是def。没有服务器的问题。它也不是网络硬件的问题。我已经改变了一切,但问题仍然存在。

没人知道?

更新3 这是完整的错误代码和堆栈跟踪(对不起,如果我的翻译缺乏一些质量:)

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)

0 个答案:

没有答案