大神们好,小弟在使用ksoap2调用webservice的接口时遇到问题,该webservice的参数为对象,我在网上查是说需要将传入的参数进行序列化。但是我依葫芦画瓢没成功。
String serverurl = "http://192.168.1.82:7001/test/print?wsdl";
String namespace = "http://print.ws.prt.tplife.com/";
String methodName = "getPostList";

PostListInfoIn aPostListInfoIn = new PostListInfoIn();

HttpTransportSE httpTranstation = new HttpTransportSE(serverurl);
httpTranstation.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject soapObject = new SoapObject(namespace, methodName);
soapObject.addProperty("arg0", aPostListInfoIn);
envelope.addMapping(namespace, "arg0", aPostListInfoIn.getClass());
envelope.bodyOut = soapObject;
envelope.dotNet = true;
try {
httpTranstation.call(namespace + methodName, envelope); if (envelope.getResponse() != null) {
Object result = envelope.getResponse();
return result;
}
} catch (Exception e)
{
e.printStackTrace();
}报错信息指向httpTranstation.call(namespace + methodName, envelope)这个函数里。
报错信息:
我用.NET WebService Studio工具查看了我调用的方法的信息:
请问:我要如何改代码,才能正确的调用到webservice的接口呢?ksoap2webserviceandroid

解决方案 »

  1.   

    看下wsdl文档上说的namespace,我感觉是你的namespace有问题
      

  2.   

    不要沉呀,哪位高人可以给我个能够调用复杂参数webservice的android的例子。小弟感激不尽。
      

  3.   

    1.NameSpace = "http://tempuri.org/"
    2.serverurl="http://192.168.1.82:7001/test/print.asmx
    你可以下载这个看看:
    http://download.csdn.net/detail/fire_fire_fire/4311576
      

  4.   

    大牛们,我再问个问题,我用httpclient的post的方式提交xml请求,响应的时候出现“请求格式无效”。我吧代码贴上来,麻烦你们帮我看看我的代码哪里错了。//执行的是这个函数
     private void httpClientPost() {
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost("http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather");
             
            try {
                ContentProducer cp = new ContentProducer() {
                    public void writeTo(OutputStream outstream) throws IOException {
                        Writer writer = new OutputStreamWriter(outstream, "UTF-16");
                         
                        /**
                         * 获取请求的xml格式数据
                         */
                        String requestXml = getRequestXml();
                        System.out.println(requestXml);
                        writer.write(requestXml);
                        writer.flush();
                    }
                };
     
                post.setEntity(new EntityTemplate(cp));
                HttpResponse response = client.execute(post);
                 
            //打印返回的xml数据
                System.out.println(EntityUtils.toString(response.getEntity()));
            } catch (IOException e) {
             System.out.println("no");
                e.printStackTrace();
            }
        }
        
        private static String getRequestXml(){
            StringBuilder sb = new StringBuilder("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
            sb.append("<soap:Header/>");
            sb.append("<soap:Body>");
            sb.append("<getWeather xmlns=\"http://WebXml.com.cn/\">");
            sb.append("<theCityCode>福州</theCityCode>");
            sb.append("<theUserID />");
            sb.append("</getWeather>");
            sb.append("</soap:Body>");
            sb.append("</soap:Envelope>");         
            return sb.toString();
        }