Rest – How to enable webHttp connection in WCF


I am developing a solution for transfering data from android phone to the server (written in C#/.NET).

I created a WCF service and testing with emulator everything worked fine. Then when I tried to login from mobile phone (connected to home wifi network) I got the following exception message:

org.apache.http.conn.HttpHostConnectException: Connection to refused

I would really appreciate if anyonecould give a look at the config file and the interface and give any advice on how to enable connection.


    <compilation debug="true"/>
        <binding name="DefaultBinding"
                 bypassProxyOnLocal="true" />
        <behavior name="RESTFriendly">
      <service name="RESTServer.LoginService">
        <endpoint address=""
                  contract="RESTServer.ILoginService" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />


public interface ILoginService
    [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/username={username}&password={password}")]
    Message Login(string username, string password);

Service implementation:

public class LoginService : ILoginService
    public Message Login(string username, string password)
        Message message = new Message();
        SQLWorks sqlWorks = new SQLWorks();
        string strSession = sqlWorks.Login(username, password);
        string strMessage;
        message.Session = strSession;
        if(strSession == "")
            strMessage = "Login failed! Please check your username/password!";
            strMessage = "Login Successful";
        message.ErrorMessage = strMessage;
        return message;

Best Solution

In order to connect to your service, it needs to be hosted on a public web server. It looks like the address you're using is a home network address, which is not accessible from the outside world (a phone).

Related Question