0

我正在使用 ksoap2 为 android 开发 Web 服务。我正在编写的代码返回一个错误(xml exeption),我不知道错误在哪里,我认为它可能是操作或 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

嗨检查下面的源代码,它的工作原理!我正在使用 android ksoap App 访问 php nusoap Web 服务。

 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 回答