【问题标题】:C# can't resolve internal domain but browser and wcf test client canC# 无法解析内部域,但浏览器和 wcf 测试客户端可以
【发布时间】:2016-03-01 13:19:10
【问题描述】:

我正在尝试使用以下代码调用内部网络服务:

using (FastquoteWcfServiceClient fastQuoteClient = new FastquoteWcfServiceClient())
{
    var request = new SearchProjectsRequest
    {
        GeoLocationDetails = new GeoLocationSearchRequest { Postcode = fullPostcode },
        PageSize = 20,
        IncludeCompletedProjects = false
    };

    try
    {
        ProjectSearchResponse response = fastQuoteClient.SearchProjects(request);

        if (response != null)
        {
            return response.Projects;
        }
    }
    catch
    {
    }
}

和配置:

<endpoint address="http://devwcfinternal/FastquoteWcfService/FastquoteWcfService.svc" 
          binding="basicHttpBinding" 
          bindingConfiguration="fastquote"
          contract="FastQuoteService.IFastquoteWcfService" 
          name="fastquoteService" />

<binding name="fastquote" 
         closeTimeout="00:01:00" 
         openTimeout="00:01:00" 
         receiveTimeout="00:10:00" 
         sendTimeout="00:01:00" 
         allowCookies="false" 
         bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard"
         maxBufferSize="2147483647" 
         maxBufferPoolSize="524288" 
         maxReceivedMessageSize="2147483647" 
         messageEncoding="Text" 
         textEncoding="utf-8" 
         transferMode="Buffered" 
         useDefaultWebProxy="true" />

我可以浏览到 url:http://devwcfinternal/FastquoteWcfService/FastquoteWcfService.svc 并运行它并调用 wcf 测试客户端中的方法,但是当我执行代码时,我收到以下错误消息:

<h3>Oops! We couldn't find <strong>devwcfinternal</strong></h3>

有谁知道什么会导致只有代码无法解析主机名?

我们的系统人员认为这可能与 IIS 有关

【问题讨论】:

  • 为了测试是否是 DNS 问题,我会在本地 lmhost 文件中设置目标主机 - 或在 wcf 配置中使用 IP(以防 IIS 响应 ip)

标签: c# wcf iis dns resolve


【解决方案1】:

事实证明,请求是通过默认代理传输的,这导致请求失败,因为代理正在将其转换为外部 url

通过将绑定更改为

<binding name="fastquote" 
     closeTimeout="00:01:00" 
     openTimeout="00:01:00" 
     receiveTimeout="00:10:00" 
     sendTimeout="00:01:00" 
     allowCookies="false" 
     bypassProxyOnLocal="false" 
     hostNameComparisonMode="StrongWildcard"
     maxBufferSize="2147483647" 
     maxBufferPoolSize="524288" 
     maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" 
     textEncoding="utf-8" 
     transferMode="Buffered" 
     useDefaultWebProxy="false" />

解决了我的问题

【讨论】:

    猜你喜欢
    • 2015-06-08
    • 2011-07-10
    • 2011-03-26
    • 2011-11-26
    • 2011-04-17
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 2012-08-23
    相关资源
    最近更新 更多