1
votes

I am trying to host a webserver with WPF on the local wifi network and expose a webservice that another device (in my case, an Android) can call while connected to the same wifi network. I have created an inbound rule on the firewall for the port I am using. The webservice call only goes through when the windows app is launched using "Run as Administrator" Is there a way I can do the same without Admin privileges? Here is my code -

public class SelfHost
{
    WebServiceHost Host;
    public void HostServer()
    {
        var hostIPadd = Util.GetLocalHostIP(); //This returns something like "http://192.168.1.2" 
        Values.SERVER_PORT_VALUE = "55000";

        var uri = new Uri(hostIPadd + ":" + Values.SERVER_PORT_VALUE);

        Host = new WebServiceHost(new Service{...}, uri);

        //Start host
        ServiceEndpoint ep = Host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
        Host.Open();
    }
}


public partial class MyWindow : Window
{

    public MyWindow()
    {
        InitializeComponent();
        StartHost();
    }

     private void StartHost()
    {
        var host = new SelfHost();

        var thServer = new System.Threading.Thread(host.HostServer);
        thServer.IsBackground = true;
        thServer.Start();
    }
}

I have created an inbound rule in the firewall with these properties
Protocol type - TCP
Local port - Specific Ports - 55000
Profiles - Public
Action - "Allow the connection"
Programs - "All programs that meet the specified conditions"

I don't quite know why the firewall ignores this exception if the app is not running in Admin. The WebServiceHost object runs fine even if it is not in Admin mode, no errors. But the webservice call never reaches the server and the request times out.

1

1 Answers

2
votes

nothing to do with the firewall, you can't open an http link in a wpf app - for security reasons

see that