2012-08-28 51 views
0

我的Android代碼無法從Android

public class MainActivity extends Activity { 

    TextView et,tv1; 
    private static String url = "//10.0.2.2:8090/WebApplication8/du"; 
    private boolean add; 
    private static final String NAMESPACE = "//db/"; 
    private static final String SOAP_ACTION = "//db/du/helloRequest"; 
    private static final String METHOD_NAME = "hello"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     // listAdapter = new ArrayAdapter<String>(this, R.layout.list_item); 
     // setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1)); 

     // setListAdapter(adapter); 

     //list1=(ListView)findViewById(R.id.list1); 
     TextView tv; 
     InputStream is = null; 

     //String[] values = new String[] { "Mercury", "Venus", "Earth", "Mars", 
     // "Jupiter", "Saturn", "Uranus", "Neptune"};  

     tv=(TextView)findViewById(R.id.tv1); 

     // Create ArrayAdapter using the planet list. 
     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
     try 
     { 
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
      request.addProperty("parameters", 51); 
      request.addProperty("username", "Rajapandian"); 
      request.addProperty("password", "Rajapandian"); 

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

      envelope.setOutputSoapObject(request); 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(url); 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
      SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
      tv.setHint("Received :" + resultsRequestSOAP.toString()); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 
} 

這裏傳遞參數的Web服務是我WSDL

<definitions targetNamespace="//db/" name="du"><types><xsd:schema><xsd:import namespace="http://db/" schemaLocation="http://localhost:8090/WebApplication8/du?xsd=1"/></xsd:schema></types><message name="hello"><part name="parameters" element="tns:hello"/></message><message name="helloResponse"><part name="parameters" element="tns:helloResponse"/></message><portType name="du"><operation name="hello"><input wsam:Action="//db/du/helloRequest" message="tns:hello"/><output wsam:Action="//db/du/helloResponse" message="tns:helloResponse"/></operation></portType><binding name="duPortBinding" type="tns:du"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="hello"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="du"><port name="duPort" binding="tns:duPortBinding"><soap:address location="http://localhost:8090/WebApplication8/du"/></port></service></definitions> 

,這裏是我的du.java

@WebService(serviceName = "du") 
public class du { 



/** 
* This is a sample web service operation 
*/ 
    @WebMethod(operationName = "hello") 
public String hello(@WebParam(name ="id",targetNamespace="http://db/")int id,@WebParam(name ="username",targetNamespace="http://db/") String username,@WebParam(name ="password",targetNamespace="http://db/")String password) { 


{ 


String result="",user="",pass=""; 

    try 
     { 

     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/users","root","789456"); 
    String query= "Insert into users(id,password,username)    values('"+id+"','"+password+"','"+username+"')"; 
     PreparedStatement stm = con.prepareStatement(query); 

    stm.executeUpdate(); 







} 
     catch(ClassNotFoundException e){ 
    System.err.println ("Sql Exception"+e); 
     } 


     catch(SQLException e){ 
    System.err.println ("Sql Exception"+e); 
     } 

    return "hey"+ id+"\n"+username+"\n"+password; 
} 
} 

    } 

當我測試這一切工作正常和數據獲取插入到MySQL數據庫,但它的問題從Android數據不會發送和null,null結果插入到MySQL表中d空響應收到的Android屏幕 在我的服務器日誌中我得到這樣的警告

WARNING: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: ://db/du/helloRequest 

請你告訴我什麼是錯

+0

能。你捕獲Android發送的SOAP請求,並將其發佈到這裏? – RajV

回答

0

連接參數缺少http標籤。

private static String url = "http://10.0.2.2:8090/WebApplication8/du"; 
    private static final String NAMESPACE = "http://db/"; 
    private static final String SOAP_ACTION = "http://db/du/helloRequest"; 
    private static final String METHOD_NAME = "hello"; 

注意:Soap Action =命名空間+方法名稱。

所以,要麼你METHOD_NAME應該是"helloRequest"SOAP_ACTION應該"http://db/du/hello"(取決於你使用什麼)。

+0

仍爲null值爲paseed –

0

對不起,我不能評論,只是回答。警告與問題無關。

我有同樣的警告。該警告只是要求您「引用」SOAP_ACTION。讓我們行動起來吧:

您的代碼:

private static final String SOAP_ACTION = "http://db/du/helloRequest"; 

的引用代碼:

private static final String SOAP_ACTION = "\"http://db/du/helloRequest\""; 

請注意\」,將發送引號服務器