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 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题