How to call your PHP service using ksoap2-android?

So far, I have created a PHP client and a VB.NET client that successfully called my PHP service. For the latter to work, I needed to use the SoapUI tool from SourceForge . He told me that my wsdl is not WS-I compliant. I do not need the Pro version for interactive testing of my service, since it allows you to directly edit the soap request. After fixing my WSDL and getting the VB.Net Android client working, it’s still a problem.

I also attached the source code for ksoap2-andriod so that I can go through debugging. This helped a little, but there are related dependencies for which the source is not included, in particular "kxml2 v1.6". If anyone can point me to the source of zip or Jar, I would appreciate it.

This is an error that I cannot get when calling a PHP web service 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 ) 

Telling me that he cannot parse WSDL \ XML - poistion @ 10.42 is the end of the discovery definition tag.

I believe that since WSDL is now WS-I compatible, the problem is with these service namespace definitions that are interpreted by Ksoap2. Here is my client code for Android.

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

* something is wrong with the return of this value, it was received, but it gives an error when transferring 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 "+"\n\n" + e.getMessage() + "/n/n" + e.getStackTrace() ;} } else {soapResponse="You are not online"; } tv.setText(soapResponse); } } 

If I am doing something dumb, and someone can point it out, I would appreciate it.

Is there a directive not to cache and reuse wsdl in Android, as in PHP?

Maybe using net beans will help, what's next when I have time. If someone can help with this, feel free 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(); 
+6
source share
2 answers

I found that the URL string should point to public php.

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

Really a very simple thing at the end in 3 weeks. Downloading the source code was essential, as it allowed me to see that the service was working. There was another problem with passing parameters, for example:

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

but that is another question.

Thanks for your comments.

+3
source

I quickly created the Restful web service. There were many reasons for developing a web service as a holiday other than SOAP. I did a very small project on SOAP to get the big picture, and then switched to quiet work, as these are more advantages. Netbeans IDEs provide very convenient tools for developing both models. Read Web Services Training Route

This link contains both a quiet and SOAP / WDSL web development service is very simple ... I hope this helps.

+3
source

Source: https://habr.com/ru/post/922894/


All Articles