我正在开发一个解决方案,用于将数据从Android手机传输到服务器(使用C#/.NET编写)。我创建了一个WCF服务,并在模拟器上进行测试,一切都正常。然后,当我尝试从连接到家庭WiFi网络的移动电话登录时,出现了以下异常消息:org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.1.5:8000 refused。如果有人能查看配置文件和接口并给出任何有关如何启用连接的建议,我将不胜感激。
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>
接口:
[ServiceContract()]
public interface ILoginService
{
[WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/username={username}&password={password}")]
[OperationContract]
Message Login(string username, string password);
}
服务实现:
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;
}
}