views:

838

answers:

2

Hi,

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 http://192.168.1.5:8000 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.

web.config:

<configuration>
<system.web>
 <compilation debug="true"/>
    </system.web>
<system.serviceModel>
 <bindings>


<webHttpBinding>
<binding name="DefaultBinding" allowCookies="true" bypassProxyOnLocal="true" />


</webHttpBinding>


 </bindings>


<behaviors>


<endpointBehaviors>
<behavior name="RESTFriendly">
  <webHttp/>
</behavior>


</endpointBehaviors>


</behaviors>


<services>



<service name="RESTServer.LoginService">
<endpoint address="" behaviorConfiguration="RESTFriendly" binding="webHttpBinding"
 bindingConfiguration="DefaultBinding" contract="RESTServer.ILoginService" />


</service>


</services>


<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
</configuration>

Interface:

[ServiceContract()]
public interface ILoginService
{
    [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/username={username}&password={password}")]
    [OperationContract]
    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!";
        }
        else
        {
            strMessage = "Login Successful";
        }
        message.ErrorMessage = strMessage;
        return message;
    }
}
A: 

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 192.168.1.5:8000 is a home network address, which is not accessible from the outside world (a phone).

Andy White
I tested it on a local network so I believe it should be accessible
niko
How did you test it? 192.168.1.5 is not the public IP address of your computer. If you go to a site like "whatismyip.com" you'll see your public IP address. In order to hit your machine from the outside world, you'll need to use the public IP address (and you may need to talk to your ISP).
Andy White
A: 

if you are using vista OS ,you have to add the address into your firewall

netsh http add urlacl url=http://+:8000/ user=DOMAIN\user

fitnet