Search code examples
c#wcfiisdnsresolve

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


I am trying to make a call to an internal webservice using the following code:

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

And config:

<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" />

I can browse to the url: http://devwcfinternal/FastquoteWcfService/FastquoteWcfService.svc and run it and invoke the method in the wcf test client but when I execute the code, I get the following error message:

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

Does anyone know what would cause only the code not to be able to resolve the hostname?

Our systems guy thinks it may be something to do with IIS


Solution

  • It turns out that the request was being piped through the default proxy which was causing the request to fail as the proxy was converting it to an external url

    By changing the binding to

    <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" />
    

    It solved my problem