从Android(Java)客户端调用Web服务(PHP和NUSOAP)时出现问题

问题描述:

我有一个php webservice

I have a php webservice

require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('hellowsdl', 'urn:hellowsdl');
// Register the method to expose
$server->register('hello',                // method name
    array('name' => 'xsd:string'),        // input parameters
    array('return' => 'xsd:string'),      // output parameters
    'urn:hellowsdl',                      // namespace
    'urn:hellowsdl#hello',                // soapaction
    'rpc',                                // style
    'encoded',                            // use
    'Says hello to the caller'            // documentation
);

function hello($name) {
        return 'Hello, ' . $name;
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);



和我的java客户端(android设备)




And my java client (android device)

private static final String SOAP_ACTION = "urn:hellowsdl#hello";
	private static final String METHOD_NAME = "hello";
	private static final String NAMESPACE = "urn:hellowsdl";
	private static final String URL = "http://127.0.0.1/www/webs.php";


	@Override
	public void onCreate(Bundle icicle)
	{
		super.onCreate(icicle);
		TextView tv = new TextView(this);
		setContentView(tv);


		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


		//SoapObject 
		request.addProperty("name", "name");


		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(URL);

		try
		{
			httpTransport.call(SOAP_ACTION, envelope);
			Object response = envelope.getResponse();
			tv.setText(response.toString());
		}

		catch (Exception exception)
		{
			tv.setText(exception.toString());
		}

	}



但我总是拒绝连接。我做错了什么?


But I always get connection refused. What am I doing wrong ?

server = new soap_server();
//初始化WSDL支持
server = new soap_server(); // Initialize WSDL support


server-> configureWSDL('hellowsdl','urn:hellowsdl');
//注册方法以公开
server->configureWSDL('hellowsdl', 'urn:hellowsdl'); // Register the method to expose


server-> register('hello',//方法名称
array('name'=>'xsd :string'),//输入参数
array('return'=>'xsd:string'),//输出参数
'urn:hellowsdl',// namespace
' urn:hellowsdl#hello',// soapaction
'rpc',// style
'coded',//使用
'向调用者说'hello'// document
);

函数你好(
server->register('hello', // method name array('name' => 'xsd:string'), // input parameters array('return' => 'xsd:string'), // output parameters 'urn:hellowsdl', // namespace 'urn:hellowsdl#hello', // soapaction 'rpc', // style 'encoded', // use 'Says hello to the caller' // documentation ); function hello(