Android KSOAP2请求PHP SOAP服务器

I am trying to create a SOAP client in my android app. I have already tested the server with php SOAP client, and it has been working. But in my android app I am still getting exceptions. Can anyone help me whats wrong and how to fix it? Thanks

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(); 
?>

Android

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:

" + result.getProperty(0).toString());
    }

}
drbz99867
drbz99867 你得到的确切例外是什么?
8 年多之前 回复

2个回答



您的URL应该是soap端点,即 http://www.domain.cz/server/server.php < / code> </ p>

您的SOAP_ACTION应包含方法名称,即 http://www.domain.cz/server/server.php/login </ code> </ p >
</ div>

展开原文

原文

Your URL should be the soap endpoint, i.e. http://www.domain.cz/server/server.php

Your SOAP_ACTION should contain the method name, i.e. http://www.domain.cz/server/server.php/login



您正在使用KSOAP(?)我推测。 我认为您需要将URL指向Web服务路径。 我看到你的URL没有WSDL。</ p>
</ div>

展开原文

原文

You are using KSOAP(?) I presumed. I think you need to point URL to the web-service path. I see no WSDL at your URL.

dppx9253
dppx9253 是的我正在使用KSOAP。 我以为我可以在没有WSDFL文件的情况下使用它。 如果KSOAP在没有WSDL的情况下无法工作,还有另外一种方法吗?
8 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐