【问题标题】:how to Consume Svc WCF service in android如何在 android 中使用 Svc WCF 服务
【发布时间】:2013-05-07 05:05:14
【问题描述】:

wsdl 网址:http://xxx.xxx.xxx/UserService.svc

我用 Ksoap 打服务...

这是我的代码:

try {
                request = new SoapObject("http://tempuri.org/", "GetUserDetailsByUserName");

                request.addProperty("username", "Prasad");
                envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(request);
                Log.i("Wsdl Response", "Wsdl Response:");
                // request.setHeader("Content-type", "application/xml");
                // Proxy px = new Proxy();

                // ?singleWsdl
                httpreq = new HttpTransportSE("http://xxx.xxx.xxx/UserService.svc");
                httpreq.debug = true;
                httpreq.call("http://tempuri.org/xxxe/GetUserDetailsByUserName", envelope);
                Log.i("Wsdl Response", ":Wsdl Response:123");
                String xml = (String) envelope.getResponse().toString();
                SoapPrimitive results = (SoapPrimitive) envelope.getResponse();
                /*
                 * if (envelope.bodyIn instanceof SoapFault) { String errormessage = ((SoapFault) envelope.bodyIn).faultstring; throw new Exception(errormessage); } IncomeLeadXMLPharsing parse = new IncomeLeadXMLPharsing(); parse.parse(xml); ResultVecotor = parse.getVector(); mHandler.post(setValuesToUi);
                 */
                Log.i("Wsdl Response", ":Wsdl Response:" + xml);
                if (progress != null) {
                    if (progress.isShowing()) {
                        progress.dismiss();
                    }
                }


            }
            catch (UnknownHostException e) {
                if (progress != null) {
                    if (progress.isShowing()) {
                        progress.dismiss();
                    }
                }
                e.printStackTrace();
            }
            catch (ConnectException e) {
                if (progress != null) {
                    if (progress.isShowing()) {
                        progress.dismiss();
                    }
                }
                e.printStackTrace();
            }
            catch (SocketException e) {
                if (progress != null) {
                    if (progress.isShowing()) {
                        progress.dismiss();
                    }
                }
                e.printStackTrace();
            }
            catch (Exception e) {
                if (progress != null) {
                    if (progress.isShowing()) {
                        progress.dismiss();
                    }
                }
                e.printStackTrace();
                System.out.print("EXCEPTION" + e);
            }

但我在 log cat 中遇到了这个异常:即使经过大量尝试,我也无法找到解决方案

05-07 10:29:22.861: WARN/System.err(635): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@3:44 in java.io.InputStreamReader@413016e0) 
05-07 10:29:22.861: WARN/System.err(635):     at org.kxml2.io.KXmlParser.require(KXmlParser.java:2046)
05-07 10:29:22.861: WARN/System.err(635):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
05-07 10:29:22.861: WARN/System.err(635):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
05-07 10:29:22.871: WARN/System.err(635):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
05-07 10:29:22.871: WARN/System.err(635):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
05-07 10:29:22.871: WARN/System.err(635):     at com.myApp.JsonService$SampleWsdlServiceAsync.doInBackground(JsonService.java:291)
05-07 10:29:22.871: WARN/System.err(635):     at com.myApp.JsonService$SampleWsdlServiceAsync.doInBackground(JsonService.java:1)
05-07 10:29:22.871: WARN/System.err(635):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
05-07 10:29:22.881: WARN/System.err(635):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-07 10:29:22.881: WARN/System.err(635):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-07 10:29:22.881: WARN/System.err(635):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
05-07 10:29:22.894: WARN/System.err(635):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-07 10:29:22.894: WARN/System.err(635):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-07 10:29:22.902: WARN/System.err(635):     at java.lang.Thread.run(Thread.java:856)

如果有人能帮到我,那就太好了。

提前致谢。

【问题讨论】:

    标签: android web-services ksoap xmlpullparser


    【解决方案1】:

    尝试更改这些行:

    我认为您的通话网址不正确:

    try {                
    
     androidHttpTransport.call("http://tempuri.org/GetUserDetailsByUserName", Envelope);
    } catch (IOException e) {
     Log.d("ErrorApp", e.getMessage().toString());
    } catch (XmlPullParserException e) {
     Log.d("ErrorApp", e.getMessage().toString());
    
    }
    
    SoapPrimitive response= (SoapPrimitive) Envelope.getResponse();
    

    【讨论】:

    • 您好 Carlos Landeras:感谢您的回复。我试过了..但我仍然面临问题。请帮我解决这个问题。//
    • 尝试将 Soap Envelope 更改为版本 12 并给我输出。信封 = 新的 SoapSerializationEnvelope(SoapEnvelope.VER12);
    • Carlos Landeras:对不起兄弟,得到相同的异常。XmlPullParser 异常与开始标记
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 2011-09-11
    • 2010-09-26
    • 1970-01-01
    • 2014-08-23
    相关资源
    最近更新 更多