当客户端调用无参的方法时,是可以的。在网页上访问带参的WebService也是可以的,客户端调试也没有任何问题,但是服务器接收到的参数一直值空的,就是接收不到。下面是本人Android客户端的核心代码,跪求高手帮忙。
public String CallWebService( String MethodName ) { System.out.println( "MethodName=" + MethodName ); //1、新建SoapObject对象,指定webservice的命名空间和调用的webservice方法名 SoapObject request = new SoapObject( Namespace, MethodName ); //2、给SoapObject对象添加参数 //Add the property to request object request.addProperty( "id", lockparkId ); //3、生成调用Webservice方法的SOAP请求信息。该信息由SoapSerializationEnvelope对象描述 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);//注意是VER11,而不是VER12 //4、设置bodyOut属性的值为SoapObject对象request envelope.bodyOut = request; //5、指定webservice的类型为dotNet envelope.dotNet = true; envelope.setOutputSoapObject( request ); // 设置请求参数 //6、创建HttpTransportSE对象,并指定WebService的WSDL文档的URL HttpTransportSE androidHttpTransport = new HttpTransportSE( WEB_SERVICE_URL ); //使用call方法调用WebService方法 try { //第一个参数不仅仅是soapAction,还要是soapAction + MethodName androidHttpTransport.call( SOAP_Action + MethodName, envelope ); } catch (HttpResponseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } //假如服务器返回的是byte[]类型 //SoapObject response = (SoapObject) envelope.bodyIn; //假如服务器返回的是String类型 try { Object response = envelope.getResponse(); result = response.toString(); // 获取从服务器端返回的XML字符串 System.out.println("Result:"+result); return result; } catch (SoapFault e) { e.printStackTrace(); } return result; }