2011-12-12 2 views
0

다음 코드를 사용하여 .net 웹 서비스에 XML 파일을 만들고 전달하고 싶습니다. 그러나, 나는 얻고이 XML 파일을 .net Web Services에서 진행하는 방법을 모른다. 이 문제를 해결하도록 도와 주시겠습니까?Android : XML 파일을 .net WebService로 전달하고 Web Service에서 XML 파일을 처리하는 방법은 무엇입니까?

public void registration(String[] data) {  

String line = "<UserData 
       Name=\"Username" Email = \"emaiAddress" Password = \"Password" + 
       "SecurityQuestion = \"Question" SAnswer = \"SAnswer"/>"; 

try { 

    DefaultHttpClient httpClient = new DefaultHttpClient(); 

    HttpPost httpPost = new HttpPost(localhost + "UserData"); 

     StringEntity se = new StringEntity(line, HTTP.UTF_8); 

     se.setContentType("text/xml"); 

    httpPost.setEntity(se); 

    HttpResponse httpResponse = httpClient.execute(httpPost); 
    HttpEntity httpEntity = httpResponse.getEntity();    

     line = EntityUtils.toString(httpEntity); 

    } catch (UnsupportedEncodingException e) {    

    } 
} 

웹 서비스에서이 XML의 속성을 가져 오는 방법을 알고 있습니다. 다음 코드를 사용하려고합니다. 그러나 붙어 어떻게 진행 해야할지 모르겠다.

//user registration 

[WebMethod] 
public void registration(XmlDocument data) 
{ 
    XmlDocument xml = data; 
    var username = xml.GetElementsByTagName("Username");    



} 

도움을 주셔서 감사합니다.

답변

0

이보십시오.,

public void registration(String[] data) {  

    String line = "<UserData 
        Name=\"Username" Email = \"emaiAddress" Password = \"Password" + 
        "SecurityQuestion = \"Question" SAnswer = \"SAnswer"/>"; 

    try { 

     DefaultHttpClient httpClient = new DefaultHttpClient(); 

     HttpPost httpPost = new HttpPost(localhost + "UserData"); 

      StringEntity se = new StringEntity(line, HTTP.UTF_8); 

      se.setContentType("text/xml"); 

     httpPost.setEntity(se); 

     HttpResponse httpResponse = httpClient.execute(httpPost); 
     HttpEntity httpEntity = httpResponse.getEntity();  

     if (httpResponse != null) {  
        InputStream in = httpResponse.getEntity().getContent(); 
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
        Document doc = builder.parse(in); 

        if (doc != null) { 

         NodeList Username_node = doc.getElementsByTagName("Username"); 
         String usrname = Username_node.item(0).getChildNodes().item(0).getNodeValue(); 
         System.out.println(""+usrname); 
        } 
       } else { 
        showAlert(thisActivity, "No response"); 
       } 

     } catch (UnsupportedEncodingException e) {    

     } 
     } 
+0

는 당신의 도움을 주셔서 감사합니다. 그러나, 나는 XML 웹 서비스에서 안드로이드 http 게시물에 xml 파일을 읽고 싶습니다. 이 일을 도와 줄 수 있어요? – user1082138

관련 문제