Pergunta

Estou desenvolvendo uma solução para transferir dados do telefone Android para o servidor (escrito em C # /. NET).

Eu criei um serviço WCF e testes com emulador tudo funcionou bem. Então, quando eu tentei o login a partir do telefone móvel (ligado à rede doméstica Wi-Fi) Eu tenho a seguinte mensagem de exceção:

org.apache.http.conn.HttpHostConnectException: Ligação ao http://192.168.1.5:8000 recusou

Eu realmente aprecio se anyonecould dar uma olhada no arquivo de configuração ea interface e dar algum conselho sobre como ativar a conexão.

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);
}

implementação de serviço:

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;
    }
}
Foi útil?

Solução

A fim de se conectar ao seu serviço, ele precisa ser hospedado em um servidor web público. Parece que o endereço que você está usando 192.168.1.5:8000 é um endereço de rede doméstica, que não é acessível a partir do mundo exterior (um telefone).

Outras dicas

Se você estiver usando o sistema operacional Vista, você tem que adicionar o endereço no seu firewall

netsh http adicionar urlacl url = http: // +: 8000 / user = domínio \ usuário

Use o seu ip LAN para conectar seu emulador com Web Service ,, Para EX: http://192.168.1.78: 8080 / webservice

Mas a sua ligação de área local deve ser permitir Goto: Control Panel \ Rede e Internet \ Conexões de rede

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top