WCF与android客户端的连接,无法将android客户端与WCF服务连接。这是我的密码

WCF与android客户端的连接,无法将android客户端与WCF服务连接。这是我的密码,android,wcf,connectivity,Android,Wcf,Connectivity,无法将android客户端与wcf服务连接。这是我的密码 @Override public void onClick(View v) { switch(v.getId()) { case R.id.btnLogin: String userName=txtUserName.getText().toString(); String password=txtPa

无法将android客户端与wcf服务连接。这是我的密码

 @Override
    public void onClick(View v) 
    {
        switch(v.getId())
        {
            case R.id.btnLogin:
                String userName=txtUserName.getText().toString();
                String password=txtPassword.getText().toString();
                if(verifyLogin(userName,password))
                {
                    lblStatus.setText("Login Successful");
                }
                else
                {
                    //lblStatus.setText("Login Failed");
                    lblStatus.setText("Login Failed");
                }
                break;
        }
    }





 public static String convertStreamToString(InputStream is)
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }

    public static boolean verifyLogin(String UserName,String Password)
    {
        try
        {
            DefaultHttpClient httpClient=new DefaultHttpClient();


HttpGet httpGet=new HttpGet("http://1.1.1.1/JSONSample/Service1.svc/checkLogin?name="+UserName+"&pass="+Password);


HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            InputStream stream=httpEntity.getContent();

            String result= convertStreamToString(stream);

            if(result.charAt(1)=='1')
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch(Exception e)
        {
            return false;
        }

    }


Also added internet permission.

Below is my wcf service:

IService1.cs

 [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "checkLogin?name={name}&pass={pass}")]
        string checkLogin(string name, string pass);


Service1.svc.cs

 public string checkLogin(string name, string pass)
        {
            DataAccess dataAccess = new DataAccess();
            return dataAccess.checkLogin(name, pass);
        }


DataAccess class :

 public class DataAccess
    {
        SqlConnection con;
        public DataAccess()
        {
            con = new SqlConnection("Data Source=RILSWDIND105\\DEVELOPER;Initial Catalog=JSONSampleDB;user id=sa;pwd=km@1234");
        }

        public string checkLogin(string userName, string password)
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            SqlCommand command = new SqlCommand("SELECT * FROM UserLogins where UserName='" + userName + "' AND Password='" + password + "'", con);
            SqlDataReader reader = command.ExecuteReader();

            if (reader.Read())
            {
                return "1";
            }
            else
            {
                return "0";
            }
        }

    }

Web.Config

<system.serviceModel>

    <behaviors>
      <serviceBehaviors>

        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>

    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="0"/>
  </system.serviceModel>
 <system.webServer>
        <directoryBrowse enabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
@覆盖
公共void onClick(视图v)
{
开关(v.getId())
{
案例R.id.btnLogin:
字符串userName=txtUserName.getText().toString();
字符串密码=txtPassword.getText().toString();
if(验证登录(用户名、密码))
{
lblStatus.setText(“登录成功”);
}
其他的
{
//lblStatus.setText(“登录失败”);
lblStatus.setText(“登录失败”);
}
打破
}
}
公共静态字符串convertStreamToString(InputStream为)
{
BufferedReader reader=新的BufferedReader(新的InputStreamReader(is));
StringBuilder sb=新的StringBuilder();
字符串行=null;
试一试{
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
}
捕获(IOE异常){
e、 printStackTrace();
}
最后{
试一试{
is.close();
}捕获(IOE异常){
e、 printStackTrace();
}
}
使某人返回字符串();
}
公共静态布尔验证登录(字符串用户名、字符串密码)
{
尝试
{
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpGet HttpGet=新的HttpGet(“http://1.1.1.1/JSONSample/Service1.svc/checkLogin?name=“+UserName+”&pass=“+Password);
HttpResponse HttpResponse=httpClient.execute(httpGet);
HttpEntity HttpEntity=httpResponse.getEntity();
InputStream=httpEntity.getContent();
字符串结果=convertStreamToString(流);
if(result.charAt(1)='1')
{
返回true;
}
其他的
{
返回false;
}
}
捕获(例外e)
{
返回false;
}
}
还增加了互联网许可。
以下是我的wcf服务:
IService1.cs
[经营合同]
[WebInvoke(Method=“GET”,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,UriTemplate=“checkLogin?name={name}&pass={pass}”)]
string checkLogin(字符串名称、字符串传递);
Service1.svc.cs
公共字符串检查登录(字符串名称、字符串传递)
{
DataAccess DataAccess=新建DataAccess();
返回dataAccess.checkLogin(名称、密码);
}
数据访问类:
公共类数据访问
{
SqlConnection-con;
公共数据访问()
{
con=newsqlconnection(“数据源=RILSWDIND105\\DEVELOPER;初始目录=JSONSampleDB;用户id=sa;pwd=km@1234");
}
公共字符串检查登录(字符串用户名、字符串密码)
{
if(con.State==ConnectionState.Closed)
{
con.Open();
}
SqlCommand=newsqlcommand(“从UserName='“+UserName+'”和Password='“+Password+'”的用户登录中选择*,con);
SqlDataReader=command.ExecuteReader();
if(reader.Read())
{
返回“1”;
}
其他的
{
返回“0”;
}
}
}
Web.Config
WCF工作正常,当我用asp.net客户端测试时,它根据参数返回0和1

当我运行android客户端时,它只是简单地说,试图连接服务,但什么也没发生


请帮助解决此问题。

是否正确使用端点

这些链接将帮助您

您好,大师先生,我只使用了您的代码,我需要为端点指定什么:这样可以吗?在那之后你必须设置行为是的,我也做了同样的。。。服务获取编译,但对话框(测试客户端)中未添加任何服务。我可以知道你的邮件id吗?如果可能的话,我会把我的代码发给你。。。可能有一些愚蠢的错误,我无法指出。请把它放在我的博客关于页面上,请使用它:)