WebService调用导致SocketException [英] WebService call resulting in SocketException

查看:223
本文介绍了WebService调用导致SocketException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一台机器上调用web服务通常在执行asp.net页面期间大约1-5次(来自VB.net)这在DEV中运行良好我无法在我们的服务器中可靠地重现现场环境,但全天我得到以下例外:

方法例外---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException:通常只允许使用每个套接字地址(协议/网络地址/端口) WWW.XXX.YYY.ZZZ 在System.Net.Sockets.Socket.InternalConnect的System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress) (EndPoint remoteEP)在System.Net.ServicePoint.ConnectSocketInternal(布尔值connectFailure,套接字s4,套接字s6,套接字和套接字,IPAddress&地址,ConnectSocketState状态,IAsyncResult asyncResult,Int32超时,异常和异常)---内部异常结束堆栈跟踪---在System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object []参数)的System.Net.HttpWebRequest.GetRequestStream()处于等等等等等等等...
我已经筋疲力尽了google& bing - 我想 - 我已经尝试实现我在互联网上找到的修复程序,我将使用以下内容扩展默认的Web服务代理:
这不起作用
我也尝试在注册表中增加MaxUserPort和TcpTimedWaitDelay,但它似乎没有帮助。

任何人都可以帮助我吗?我真的不明白这个问题。我认为这种情况,从网页调用web服务是一种相当普遍的做法,我不会遇到看起来像基本管道的错误。

客户端是asp.net 3.5 / win2k3 r2。
服务器是as400 / apache tomcat 4

I am calling a webservice on another machine usually about 1-5 times during the execution of an asp.net page (from VB.net) This works well in DEV and I am not able to reliably reproduce in our live environment but throughout the day I get the following exception :

    Method Exception ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted WWW.XXX.YYY.ZZZ
    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream() at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at blah blah blah...

I have exhausted google & bing - I think - I have tried implementing a fix I found on the internet, where I'm extending the default webservice proxy with the following :
this didn't work

I've also tried increasing MaxUserPort and TcpTimedWaitDelay in the registry, but it doesn't seem like it has helped.

Can anyone help me? I don't really understand this problem. I figure that this scenario, calling a webservice from a webpage would be a fairly common practice, and that I wouldn't run into errors which look like basic plumbing.

client is  asp.net 3.5 / win2k3 r2.
server is as400 / apache tomcat 4

Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Partial Public Class lookup
    Inherits originalLookup
    Private Shared m_LastBindPortUsed As Integer
    Protected Overrides Function GetWebRequest(ByVal uri As System.Uri) As System.Net.WebRequest
        Dim webreq As HttpWebRequest = CType(MyBase.GetWebRequest(uri), HttpWebRequest)
        webreq.KeepAlive = True
        webreq.ServicePoint.BindIPEndPointDelegate = New BindIPEndPoint(AddressOf BindIPEndPointCallback)
        Return webreq
    End Function
    Public Shared Function BindIPEndPointCallback(ByVal servicePoint As ServicePoint, ByVal remoteEndPoint As IPEndPoint, ByVal retryCount As Integer) As IPEndPoint
        Dim port As Integer = Interlocked.Increment(m_LastBindPortUsed) 'increment
        Interlocked.CompareExchange(m_LastBindPortUsed, 5001, 65534)
        If (remoteEndPoint.AddressFamily = AddressFamily.InterNetwork) Then
                Return New IPEndPoint(IPAddress.Any, port)
        Else
                Return New IPEndPoint(IPAddress.IPv6Any, port)
        End If
    End Function
End Class

推荐答案

为什么你甚至在本地绑定一个端口?看起来你正在从5001-65535的非保留端口范围内骑行。但问题是,你为什么要这样做?
Why are you even binding to a port locally? Looks like you are cycling through the non-reserved port range from 5001-65535. But the question is, why are you doing this?


这篇关于WebService调用导致SocketException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆