Search code examples
c#.netwcflocalhostwcf-binding

In C# WCF service If HostNameComparisonMode = "HostNameComparisonMode.Exact", not able to access URL in browser saying 404 Error


In WCF service If HostNameComparisonMode = "HostNameComparisonMode.Exact", not able to access URL in browser saying 404 Error.

But when I am changing URL path with some different name then its working like the scenario given below

If URL is "http://localhost:8006/ComService/Service" then after WCF service being hosted I am not able to hit the URL in browser If HostNameComparisonMode = "HostNameComparisonMode.Exact" but Its working fine with HostNameComparisonMode = "HostNameComparisonMode.StrongWildcard"

But, If I change URL like "http://localhost:8006/ComService/Service123" then Its working fine with HostNameComparisonMode = "HostNameComparisonMode.Exact"


Solution

  • HostNameComparisonMode:This value indicates whether to use the hostname to access the service when matching the URI.

    For example:

    The endpoint address exposed by the server is net.tcp://localhost/Test, and clients can use different host names to access this service endpoint, as follows:

    net.tcp://localhost/Test

    net.tcp://127.0.0.1/Test

    net.tcp://computername/Test

    All of the above addresses allow clients to access the specified service endpoint.This is because the default value of the hostnamecomparisonmode property is strongwildcard, which means that the hostname match is ignored.

    If the value of hostnamecomparisonmode is exact, the hostname must match exactly.If the host name of the endpoint address exposed by the server is localhost, the client's endpoint address must also use localhost. Otherwise, the client will have endpointnotfoundexception.

    For more information about HostNameComparisonMode,Please refer to the following link:

    https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.hostnamecomparisonmode?view=netframework-4.8#System_ServiceModel_HostNameComparisonMode_StrongWildcard