C# 无法解析内部域,但浏览器和 wcf 测试客户端可以

C# can't resolve internal domain but browser and wcf test client can

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

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 有关

事实证明,请求是通过默认代理传输的,这导致请求失败,因为代理正在将其转换为外部 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" />

它解决了我的问题