简体   繁体   中英

Limit WCF service calls to local clients

I am trying to open WCF Service for local use only.

I cant seem to find a way to make it listen on localhost only (not allow remote connections to my WCF host)

Here is an example code :

var baseUri = new Uri("http://127.0.0.1:9001");
var webHost = new WebServiceHost(typeof(MyService), baseUri);
webHost.AddServiceEndpoint(typeof(MyService), new WebHttpBinding(), string.Empty);
webHost.Open();
Console.WriteLine("press any key to exit");
Console.ReadLine();

looking on the resource Monitor shows that it listen to "unspecified ip".

How can i force it to listen on localhost only ?

You can set HostNameComparisonMode on your WebHttpBinding to Exact , this includes the host name in endpoint matching.

The HostnameComparisonMode value that indicates whether the hostname is used to reach the service when matching on the URI. The default value is StrongWildcard, which ignores the hostname in the match.

But using Named Pipes is better in this case. For more info see msdn .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM