ksoap2を使用してAndroid用のWebサービスに取り組んでいます。書いているコードがエラー (xml 例外) を返しています。エラーの場所がわかりません。アクションまたは URL である可能性があります。私は完全なPHP Webサービスの例を探していましたが、役に立ちませんでした
これはserver.phpファイルです
<?php
// Pull in the NuSOAP code
require_once("lib/nusoap.php");
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('server', 'urn:server');
// Put the WSDL schema types in the namespace with the tns prefix
$server->wsdl->schemaTargetNamespace = 'urn:server';
// Register the method to expose
$server->register('pollServer',
// method name
array('value' => 'xsd:string'),
// input parameters
array('return' => 'xsd:string'),
// output parameters
'urn:server',
// namespace
'urn:server#pollServer',
// soapaction
'rpc',
// style
'encoded',
// use
'Says hello to the caller'
// documentation
);
// Define the method as a PHP function
function pollServer($value){
if($value['value'] == 'Good'){
return $value['value'].""."The value of the server poll resulted in good information";
}
else{
return $value['value'].""."The value of the server poll showed poor information";
}
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA);
?>
これはクライアントの Java ファイルです。
package com.restaurantApp;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;
public class Example {
private static final String SOAP_ACTION = "urn:server#pollServer";
private static final String METHOD_NAME = "pollServer";
private static final String NAMESPACE = "urn:server";
private static final String URL = "http://sara-alabbasi.com/server.php";
public Example(){
SoapObject soapclient = new SoapObject(NAMESPACE,METHOD_NAME);
//Yes you need this one in order to send the whole string or else only the first letter
//is going to be send
SoapObject parameters = new SoapObject(NAMESPACE, METHOD_NAME);
parameters.addProperty("value","Good");
soapclient.addProperty(METHOD_NAME,parameters);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(soapclient);
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
try {
httpTransportSE.call(SOAP_ACTION, envelope);
Log.v("TEST","runs ok attributes "+envelope.getResponse().toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.v("TEST","io wrong");
} catch (XmlPullParserException e) {
Log.v("TEST","xml wrong");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}