0

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

}

}
4

1 に答える 1

0

こんにちは、以下のソースコードをチェックしてください、それは動作します!androidksoapAppを使用してphpnusoapWebサービスにアクセスしています。

 package org.ralapanawa.mobile.android;

 import android.app.Activity;
 import android.os.Bundle;
 import android.util.Log;

 import org.ksoap2.SoapEnvelope;
 import org.ksoap2.serialization.SoapObject;
 import org.ksoap2.serialization.SoapSerializationEnvelope;
 import org.ksoap2.transport.HttpTransportSE;

public class CompareLast5DaysWater extends Activity {

private static final String SOAP_ACTION = "urn:Ralamobile#graphfunc";
private static final String METHOD_NAME = "graphfunc";
private static final String NAMESPACE = "urn:Ralamobile";
private static final String URL = "http://175.157.219.126:8099/Ralapanawa_SOAP/Ralapanawalogin.php";

//http://175.157.219.126:8099/Ralapanawa_SOAP/Ralapanawalogin.php

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.compare_water_level);

    getEncodedImageFromService("IRT001");
}

public void getEncodedImageFromService(String imageID) {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("date1", imageID);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
    } catch (Exception e) {
        e.printStackTrace();
    }

    SoapObject result;
    result = (SoapObject) envelope.bodyIn;

    if (result != null) {
        String encodedImage = result.getProperty(0).toString();
        Log.v("TAG", encodedImage);
    }
  }
}
于 2012-08-10T12:16:43.970 に答える