【问题标题】:Android KSOAP2 request to PHP SOAP server对 PHP SOAP 服务器的 Android KSOAP2 请求
【发布时间】:2012-04-18 12:59:46
【问题描述】:

我正在尝试在我的 android 应用程序中创建一个 SOAP 客户端。我已经用 php SOAP 客户端测试了服务器,它一直在工作。但在我的 android 应用程序中,我仍然遇到异常。谁能帮助我出了什么问题以及如何解决?谢谢

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

}

【问题讨论】:

  • 您遇到的确切异常是什么?

标签: java php android soap ksoap2


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我猜你正在使用 KSOAP(?)。我认为您需要将 URL 指向 Web 服务路径。我在您的 URL 中没有看到 WSDL。

    【讨论】:

    • 是的,我正在使用 KSOAP。我认为我可以在没有 WSDFL 文件的情况下使用它。如果没有 WSDL,KSOAP 不能工作,还有其他方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    相关资源
    最近更新 更多