2012-04-18 15 views
4

私のアンドロイドアプリでSOAPクライアントを作成しようとしています。私はすでにPHPのSOAPクライアントを使ってサーバをテストしています。しかし、私のアンドロイドアプリでは、私はまだ例外を取得しています。誰かが私に何が間違って、それを修正する方法を助けることができますか?おかげPHP SOAPサーバーへのAndroid KSOAP2リクエスト

PHP

<?php 
class service 
{  
public function service() 
{ } 

public function login($nickname, $password) 
{ 

    $sql = "select nick from user 
    where 
    nick =\"$nick\" 
    and 
    pass = \"$password\""; 

    if (($result = $this->db->query($sql)) && ($result->num_rows == 1)) 
     return true; 
    else 
     return false; 
} 
} 

$server = new SoapServer(null, array(
'uri' => "urn://www.domain.cz", 
'soap_version' => SOAP_1_2) 
);    
$server->setClass("service");  
$server->handle(); 
?> 

アンドロイド

private static String SOAP_ACTION = "http://www.domain.cz/server/server.php"; 
    private static String NAMESPACE = "urn://www.domain.cz"; 
    //need fix namespace to work, final solution 
    // private static String NAMESPACE = "http://www.domain.cz/server/"; 
    private static String METHOD_NAME = "login"; 
    private static String URL = "http://www.domain.cz"; 

public void Connect() 
{ 
    //Initialize soap request + add parameters 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    //Use this to add parameters 
    request.addProperty("nick","peter"); 
    request.addProperty("password","somepassword"); 

    //Declare the version of the SOAP request 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 
    envelope.setOutputSoapObject(request); 

    //Needed to make the internet call 
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    try { 
      //this is the actual part that will call the webservice 
      androidHttpTransport.call(SOAP_ACTION, envelope);//HERE is xmlpullparserexception after a while 
    } catch (Exception e) { 
      e.printStackTrace(); 
    } 

    // Get the SoapResult from the envelope body. 
    SoapObject result = (SoapObject)envelope.bodyIn; 

    if(result != null){ 
      TextView t = (TextView)this.findViewById(R.id.resultbox); 

      //Get the first property and change the label text 
      t.setText("SOAP response:\n\n" + result.getProperty(0).toString()); 
    } 

} 
+1

、あなたのSOAP_ACTIONは、メソッド名が含まれている必要があり、すなわちhttp://www.domain.cz/server/server.php

、SOAPエンドポイントである必要があり、あなたが取得している_exact_例外とは何ですか? –

答えて

2

あなたのURLは、すなわちhttp://www.domain.cz/server/server.php/login

0

あなたは、私が推測さKSOAP(?)を使用しています。 URLをWebサービスのパスにする必要があると思います。私はあなたのURLでWSDLを見ません。

+0

はい私はKSOAPを使用しています。 WSDFLファイルなしでも使えると思った。 KSOAPがWSDLなしで動作しない場合、別の方法がありますか? –

関連する問題