drjltlm156790 2012-08-15 01:42
浏览 58
已采纳

如何使用kso​​ap2-android正确调用我的PHP Web服务?

So far I have created a PHP client, and a VB.NET client which both successfully call my PHP web-service. To get the latter to work I needed to use the SoapUI tool from SourceForge. It told me that my wsdl was not WS-I compliant. I did not need the Pro version to test my service interactively as it allows you to directly edit the soap request. After fixing my WSDL and getting my VB.Net client functioning android is still a problem.

I also attached the source code for ksoap2-andriod so that I could step through while debugging. It helped a little but there are bundled dependencies for which the source is not included, in particular "kxml2 v1.6". If anyone can point me to a source zip or Jar for that I'd appreciate it.

This is the error I cant get past when calling the PHP webservice from my android client.

  org.xmlpull.v1.XmlPullParserException: expected: START_TAG   {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <definitions name='naturallyIrrationalsoapserver' targetNamespace='http://www.naturallyIrrational.com'>@10:42 in java.io.InputStreamReader@44dce560)

Its telling me it cant parse the WSDL\XML - the poistion @10.42 is the end of the opening definitions tag.

I believe that as the WSDL in now WS-I compliant that the problem is withing this service namespace definitions as interpreted by Ksoap2. Here is my android client code used to call it.

public class SoapClientActivity extends Activity {
      @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = (TextView) findViewById(R.id.myText);
        String soapResponse="";
        final String METHOD_NAME = "getArrval";
        final String SOAP_ACTION = "http://www.naturallyIrrational.com/naturallyIrrationalsoapserver.wsdl";
        final String NAMESPACE = "http://www.naturallyIrrational.com";

* This next line was incorrect and should point to http://www.naturallyIrrational.com/naturallyIrrationalsoapserver.php *

        final String URL = "http://www.naturallyIrrational.com/naturallyIrrationalsoapserver.wsdl";

        if (InternetStatus.getInstance(this).isOnline(this)) {

            try{                            
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


                    PropertyInfo pi = new PropertyInfo();
            pi.setName("valname");
            pi.setValue("rt2");
            pi.setType(String.class);
            request.addProperty(pi);    

                 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);  
                    envelope.dotNet=false;
                    envelope.setOutputSoapObject(request); 
                    HttpTransportSE andHttpTransport = new HttpTransportSE(URL); 
                    andHttpTransport.debug = true;
                    andHttpTransport.call(SOAP_ACTION, envelope);

* there is something wrong with returning this value, it has been received but throws an error when passed back from ksoap *

 soapResponse = (String) envelope.getResponse();  //Exception is thrown here  
                        String strrequest = andHttpTransport.requestDump;
                        String strresponse = andHttpTransport.responseDump;

            }catch(Exception e){soapResponse = "Nope not working "+"

" + e.getMessage() + "/n/n" + e.getStackTrace() ;}
            } else {soapResponse="You are not online"; }   


        tv.setText(soapResponse);    
    }
}

If I am doing something dumb and some one can point it out I'd appreciate it.

Is there a directive to not cache and reuse wsdl in Android like there is in PHP?

Maybe using net beans will help, that's next when I have time. If anyone can please help in the interim, don't hesitate to suggest something.

<?php
class naturallyIrrational {
  private $arrval = array("pi" => 3.1415,"e" =>  2.7183, "rt2" => 1.414, "phi" => 1.618 );  
  function getIrrationalvalue($valname) {
$myFile = "logFile.html";
$fh = fopen($myFile, 'a') or die("can't open file");
$datq = date('m/d/Y h:i:s a', time());
fwrite($fh, $datq);
if (isset($this->arrval[$valname])) {

$stringData = " ".$valname." = ".$this->arrval[$valname]."<br/>";
fwrite($fh, $stringData);
fclose($fh);      
return $this->arrval[$valname];
    } else {
    throw new SoapFault("Server","Unknown Symbol '$valname'.");
    }
  }
}
$server = new SoapServer("naturallyIrrational.wsdl");
$server->setClass("naturallyIrrational");
$server->handle();
  • 写回答

2条回答 默认 最新

  • douwen1915 2012-08-20 03:26
    关注

    I discovered that the URL string needs to point at the public php.

    final String URL = "http://www.naturallyIrrational.com/naturallyIrrationalsoapserver.php";

    Really a very simple thing in the end after 3 weeks. Downloading the source code was essential as it allowed me to see the service is functioning. There was/is another issue regarding passing parameters, like this:

    PropertyInfo pi = new PropertyInfo();
    pi.setName("valname");
    pi.setValue("rt2");
    pi.setType(String.class);
    

    but that is a different question.

    Thank you for your comments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动