2011-08-08 51 views
0

我正在開發一個應用程序來使用Web服務,如何使用下面的Web服務? http方法或ksoap2?我試過Ksoap2,似乎無法正確提取此Web服務,任何人都可以幫助解決這個問題?提前致謝。如何在Android中使用此WebService?

這裏是WSDL:https://integrator-ut.vegaconnection.com/Authentication.svc?wsdl

是那個NAME_SPACE是: 「http://tempuri.org/」 的方法是CreateToken?並且SOAP_ACTION是http://tempuri.org/IAuthentication/CreateToken?...

回答

0

如果你不想使用KSOAP,您可以使用HttpURLConnection類和InputStream的

 HttpURLConnection my_httpConnection = (HttpURLConnection) new URL("https://integrator-ut.vegaconnection.com/Authentication.svc?wsdl").openConnection(); 
     my_httpConnection.setRequestMethod("POST"); 
     my_httpConnection.setDoInput(true); 
     my_httpConnection.setDoOutput(true); 
     my_httpConnection.setRequestProperty("Content-type", "text/xml; charset=utf-8"); 



     OutputStream my_outPutStream = this.my_httpConnection.getOutputStream(); 
     Writer my_writer = new OutputStreamWriter(my_outPutStream); 
     my_writer.write(YOUR_REQUEST); //YOUR_REQUEST is a String 
     my_writer.flush(); 
     my_writer.close();   

     BufferedReader my_bufferReader = new BufferedReader(new InputStreamReader(this.my_httpConnection.getInputStream())); 
     char[] buffer = new char[10000]; 
     int nbCharRead=0; 
     try 
     { 
      while((nbCharRead = my_bufferReader.read(buffer, 0, 10000)) != -1) 
      { 
       /* Your treatement : saving on a file/arraylist/etc 

      } 
     } 

你必須使字符串YOUR_REQUEST基於要恢復

它看起來就像

<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" ... > 
<soapenv:Header/>  
<soapenv:Body> 
... 
</soapenv:Body> 
</soapenv:Envelope> 
1

請發佈您的web服務方法代碼。

**Sample web service method** 

public String Login(string userName, string pwd) throws SoapFault 
{   

    String data = ""; 

    String serviceUrl = "https://abc.com/xyz.svc"; 

    String serviceNamespace = "http://tempuri.org/"; 

    String soapAction = "http://abc.org/IAuthentication/CreateToken"; 

    String type_of_soap = "CreateToken"; 

    try 
    { 
     SoapObject Request = new SoapObject(serviceNamespace, type_of_soap); 
      //txtUserName,txtPassword these two are edit text ref variables but these are decalred before of this. 
      Request.addProperty("userName", txtUserName.getText().toString());  
      Request.addProperty("password", txtPassword.getText().toString()); 


     System.out.println("GetRestaurantDetails:"+Request.toString()); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = true; 
     envelope.setOutputSoapObject(Request); 

     try 
     { 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(serviceUrl); 
      androidHttpTransport.call(soapAction, envelope); 
     } 
     catch(Exception e) 
     { 
      System.out.println("Webservice calling error ->"+e.toString()); 
     } 

     SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
     data = response.toString(); 
     System.out.println("GetRestaurantDetails:"+response.toString()); 
     tv.setText(data);//this text view can be declared before this. 

    } 
    catch(Exception e) 
    { 
     System.out.println("Soap Method Error ->"+e.toString());  
    }   
    return data; 
} 
+0

[的WebMethod] public string Login(string userName,string pwd) { string msg = string.Empty; 嘗試 { Authentication.Authentication auth = new Authentication.Authentication(); Authentication.LoginToken login = auth.CreateToken(userName,pwd); msg =「登錄成功」; (例外ex) { msg = ex.Message; } return msg; } – jalakam

+0

你正在使用哪種工具進行Web服務方法(如ksaop)? – naresh

+0

實際上基於那個WSDL URL我想出來createToke方法... – jalakam

相關問題