2012-09-10 4 views
0

wcf 서비스로 안드로이드 클라이언트를 연결할 수 없습니다. 여기 내 코드가있다. 난 asp.net 클라이언트와 동일한 시험시WCF 안드로이드 클라이언트와 연결, 안드로이드 클라이언트와 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;[email protected]"); 
     } 

     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> 

WCF는 그 파라미터에 따라 0 & 1 반환, 잘 작동된다.

내 안드로이드 클라이언트를 실행할 때 단순히 서비스 연결을 시도하고 있지만 아무 일도 일어나지 않는 것입니다.

동일한 문제를 해결하는 데 도움주세요.

답변

1

엔드 포인트를 올바르게 사용하고 있습니까?

이러한 링크는 당신에게 Part1 Part2

+0

안녕하세요 씨 전문가 도움이 될 것입니다, 필자 통해 UR 코드를 사용하는 경우에만, 내가 뭘 끝점에 대해 지정해야이 괜찮습니다? <서비스 명 = "JSONSample.Service1"behaviorConfiguration = "JSONSample.Service1Behavior"> <종점 어드레스 = ""바인딩 = "으로 WebHttpBinding"계약 = "JSONSample.IService1"behaviorConfiguration = "웹"> <엔드 포인트 주소 = "MEX는"바인딩 = "mexHttpBinding"계약 = "IMetadataExchange"/> 그 이후 user1559414

+0

당신이 행동 HTTP를 설정해야합니다 : // guruparan.blog.com/files/2012/03/4.png –

+0

yess 나는 똑같은 ... 서비스를했다. 컴파일하지만 대화 상자 (테스트 클라이언트)에 서비스가 추가되지 않았습니다. 나는 ur 메일 ID를 가능한 한, 내 코드를 보낼 것입니다 ... 거기에 어리석은 실수가있을 수 있습니다, 어떤 지적 할 수 없습니다. Pls. – user1559414