2011-10-12 3 views
0

약간의 문제가 있습니다. 나는 첫 번째 Android 앱과 첫 번째 WCF 서비스를 동시에하고 있습니다. 나는 다음과 같은 서비스 계약이 ... 나와 함께 베어하십시오Android 클라이언트에서 웹 서비스 호출

[ServiceContract] 
    public interface ILoginService 
    { 

     [OperationContract] 
     string Login(string username, string password); 

     // TODO: Add your service operations here 
    } 

내가 내 안드로이드 응용 프로그램에서이를 호출하고 사용자 이름과 암호 매개 변수를 전달하고자합니다. 1.이 작업이 작업에 적합한 것입니까? 2. 누군가 Android를 통해이 WCF 서비스를 호출하는 방법에 대한 자습서/코드 샘플을 가르쳐 주시겠습니까?

감사합니다.

편집 : 좀 더 가까울 지 모르지만 나는 여전히 길을 잃었습니다. 계약 : : 지금 뭐가 잘못 아무 생각

public LoginResponse RemoteLogin(String username, String password) 
    { 
     loginParameters = "/LoginService/username=" + username + "&password=" + password; 


     HttpClient httpclient = new DefaultHttpClient(); 
     HttpGet httpget = new HttpGet(serviceAddress + loginParameters); 

     HttpResponse response; 

     LoginResponse loginResponse = null; 

     try 
     { 
      response = httpclient.execute(httpget); 

      HttpEntity entity = response.getEntity(); 

      if(entity != null) 
      { 
       InputStream instream = entity.getContent(); 
       String result = convertStreamToString(instream); 
       JSONObject json = new JSONObject(result); 

       // Parsing 
       JSONArray nameArray = json.names(); 
       JSONArray valArray = json.toJSONArray(nameArray); 

       loginResponse = new LoginResponse(valArray.getBoolean(1), valArray.getString(0), valArray.getString(2)); 


       instream.close(); 
      } 

     } 
     catch(Exception e) 
     { 
      loginResponse = new LoginResponse(); 
      String sDummy = e.toString(); 
     } 
     return loginResponse; 
    } 

:

[OperationContract] 
     [WebGet(ResponseFormat= WebMessageFormat.Json, 
      UriTemplate="/LoginService/?username={username}&password={password}")] 
     Response Login(string username, string password); 

가 그럼 난 안드로이드에서 서비스를 호출을 여기에 내가 지금까지 가지고있는 것입니다.

답변

0

문제를 실제로 해결하지 못했습니다. 그냥 밟은 것뿐입니다. web.config에서 ServiceModel과 관련된 작업을 제거하고 ServiceHostFactory 지시문을 SVC 파일에 추가했습니다. 그것은 트릭을했다. 이제 모든 것이 작동합니다. 일종의 구성 문제 였을 것입니다.

+0

샘플 코드를 제공해 주시겠습니까? –

+0

android.please에서 wcf 서비스로 시작하는 방법을 설명하고 몇 가지 단계를 시작하십시오. 나는 이것에 관해 어떤 생각도 가지지 않고있다. –