How to enable webHttp connection in WCF?

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

I created a WCF service and testing with the emulator everything worked fine. Then, when I tried to log in from a mobile phone (connected to my home Wi-Fi network), I received the following error message:

org.apache.http.conn.HttpHostConnectException: connection to http://192.168.1.5:8000 refused

I would really appreciate it if someone did not review the configuration file and interface and give any recommendations for connecting.

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;
    }
}
+3
source share
3 answers

, -. , , 192.168.1.5:8000, , ().

0

Vista,

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

0

Use your LAN ip to connect your emulator to the web service. For EX: http://192.168.1.78:8080/webservice

But your LAN connection must be turned on. Go to: Control Panel \ Network and Internet \ Network Connections

0
source

Source: https://habr.com/ru/post/1705229/


All Articles