首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TcpClient在web服务方法上失败

TcpClient在web服务方法上失败
EN

Stack Overflow用户
提问于 2011-02-15 11:55:32
回答 1查看 881关注 0票数 2

我还有下一个问题--我尝试在我的web服务方法中使用外部程序集(Web服务在LAN中工作)。此外部程序集在其内部组件中使用TcpClient访问外部IP地址。但不幸的是。创建TcpClient失败。

System.Net.Sockets.SocketException被捕获Message=A套接字操作遇到了死网络xxx.xxx:xxxx Source=System ErrorCode=10050 NativeErrorCode=10050 StackTrace:вSystem.Net.Sockets.TcpClient..ctor(String hostname,Int32端口)

通过代理Microsoft ISA Server实现局域网对外部网络的访问。在控制台应用程序中,所有工作正常,但是web服务方法出现异常:(我试图在web.config文件中使用下一个参数:

代码语言:javascript
复制
<?xml version="1.0"?>
<configuration>

  <appSettings/>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" >

    </compilation>
    <authentication mode="Windows"/>
    <identity impersonate="true" userName="domain\User" password="password"/>
  </system.web>

  <system.net>
    <defaultProxy useDefaultCredentials="true">
      <proxy proxyaddress="http://isa-server:8080/" bypassonlocal="True" usesystemdefault="True"  />
    </defaultProxy>
  </system.net>
</configuration>

但也不幸的是。奇怪的是,来自WebRequest类的请求是以正常方式执行的。TcpClient类中的问题。

代码语言:javascript
复制
 [WebMethod]
        public string Test()
        {
            // This code works fine
            var request = WebRequest.Create("http://www.google.ru");
            var response = (HttpWebResponse)request.GetResponse();
            Debug.Assert(response.StatusDescription.ToUpper() == "OK");
            // But this rise exception
            var a = new TcpClient("XXX.XXX.XXX.XXX", XXX).GetStream().CanRead;
        }

我也尝试过在web服务方法中手工模拟,但也没有结果。

代码语言:javascript
复制
new WindowsIdentity(WindowsIdentity.GetCurrent(true).Token).Impersonate();

有人能帮我吗?ISA代理服务器可能存在问题,参数不正确?我看了ISA服务器日志,似乎最普通的web服务方法甚至没有进入代理服务器。可能是面临同样挑战的人。谢谢你,为我的错误英语道歉!

EN

回答 1

Stack Overflow用户

发布于 2011-03-19 16:15:53

从代理地址中删除尾随斜杠,如下所示

代码语言:javascript
复制
<proxy proxyaddress="http://isa-server:8080" 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5003316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档