2016-03-03 5 views
0

Хорошо,XmlPullParserException Java/Android WCF соединения с KSOAP2

Я был на этом ЧАСОВ дыбом и не получили абсолютно нигде с. Я пытаюсь подключить веб-службу WCF к моему приложению Android через ksoap2.

Я использовал эту ссылку в качестве руководства, чтобы помочь мне: http://www.prandroid.com/2014/04/how-to-communicate-wcf-webservices-in.html

Вот мой код:

package com.example.xxx.test; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 
import android.app.Activity; 
import android.app.ProgressDialog; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.widget.TextView; 

public class Test extends Activity { 

    public class SoapTask extends AsyncTask<Void, Void, Void> { //NOTE: LINE 27 
     private final ProgressDialog dialog = new ProgressDialog(Test.this); 
     protected void onPreExecute() { 

      this.dialog.setMessage("Checking in..."); 
      this.dialog.show(); 

     } 

     @Override 
     protected Void doInBackground(Void... arg0) { 
      try{ 
       WebServiceCallExample(); //NOTE: LINE 39 THIS IS WHERE I THINK THE PROBLEM IS 
      }catch (Exception e){ 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     protected void onPostExecute(Void result) { 
      TextView tv = (TextView) findViewById(R.id.Result); 
      tv.setText(test_string); 
      if (this.dialog.isShowing()){ 
       this.dialog.dismiss(); 
      } 
     } 

    } 

    private String test_string; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_test); 
     new SoapTask().execute(); 
    } 

    @SuppressWarnings("deprecation") 
    public void WebServiceCallExample() { 
     final String NAMESPACE = "http://tempuri.org/"; 
     final String URL = "http://[IP Address]/MobileServicexxxxxxxxxxxx.svc"; 
     final String METHOD_NAME = "GetServiceOrders"; 
     final String SOAP_ACTION = "http://tempuri.org/IMobileService/GetServiceOrders"; 

     SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); 

    /* Set the web service envelope */ 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 
     envelope.dotNet = true; 
     envelope.setOutputSoapObject(Request); 
     System.out.println("Request::" + Request.toString()); 

     HttpTransportSE httpTransport = new HttpTransportSE(URL); 
     try{ 
      httpTransport.call(SOAP_ACTION, envelope); //NOTE: LINE 82 THIS IS WHERE I THINK THE PROBLEM IS 
      //SoapObject response = (SoapObject) envelope.getResponse(); 
      SoapPrimitive sp = (SoapPrimitive) envelope.getResponse(); 

      SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
      System.out.println("Response::" + resultsRequestSOAP.toString()); 
      test_string = sp.toString(); 
     }catch (Exception e){ 
      System.out.println("Testing"); 
      e.printStackTrace(); 

     } 
    } 
} 

Вот мой XML

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="MobileService" targetNamespace="http://tempuri.org/"> 
<wsdl:types> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/"> 
<xs:import namespace="http://schemas.datacontract.org/2004/07/MobileWebService"/> 
<xs:element name="GetServiceOrders"> 
<xs:complexType> 
<xs:sequence> 
<xs:element minOccurs="0" name="resource_No" nillable="true" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
<xs:element name="GetServiceOrdersResponse"> 
<xs:complexType> 
<xs:sequence> 
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/MobileWebService" minOccurs="0" name="GetServiceOrdersResult" nillable="true" type="q1:ArrayOfserviceOrderCT"/> 
</xs:sequence> 
</xs:complexType> 
</xs:element> 
</xs:schema> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/"> 
<xs:element name="anyType" nillable="true" type="xs:anyType"/> 
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/> 
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/> 
<xs:element name="boolean" nillable="true" type="xs:boolean"/> 
<xs:element name="byte" nillable="true" type="xs:byte"/> 
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/> 
<xs:element name="decimal" nillable="true" type="xs:decimal"/> 
<xs:element name="double" nillable="true" type="xs:double"/> 
<xs:element name="float" nillable="true" type="xs:float"/> 
<xs:element name="int" nillable="true" type="xs:int"/> 
<xs:element name="long" nillable="true" type="xs:long"/> 
<xs:element name="QName" nillable="true" type="xs:QName"/> 
<xs:element name="short" nillable="true" type="xs:short"/> 
<xs:element name="string" nillable="true" type="xs:string"/> 
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/> 
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/> 
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/> 
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/> 
<xs:element name="char" nillable="true" type="tns:char"/> 
<xs:simpleType name="char"> 
<xs:restriction base="xs:int"/> 
</xs:simpleType> 
<xs:element name="duration" nillable="true" type="tns:duration"/> 
<xs:simpleType name="duration"> 
<xs:restriction base="xs:duration"> 
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/> 
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/> 
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/> 
</xs:restriction> 
</xs:simpleType> 
<xs:element name="guid" nillable="true" type="tns:guid"/> 
<xs:simpleType name="guid"> 
<xs:restriction base="xs:string"> 
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/> 
</xs:restriction> 
</xs:simpleType> 
<xs:attribute name="FactoryType" type="xs:QName"/> 
<xs:attribute name="Id" type="xs:ID"/> 
<xs:attribute name="Ref" type="xs:IDREF"/> 
</xs:schema> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/MobileWebService" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/MobileWebService"> 
<xs:complexType name="ArrayOfserviceOrderCT"> 
<xs:sequence> 
<xs:element minOccurs="0" maxOccurs="unbounded" name="serviceOrderCT" nillable="true" type="tns:serviceOrderCT"/> 
</xs:sequence> 
</xs:complexType> 
<xs:element name="ArrayOfserviceOrderCT" nillable="true" type="tns:ArrayOfserviceOrderCT"/> 
<xs:complexType name="serviceOrderCT"> 
<xs:sequence> 
<xs:element minOccurs="0" name="_bill_to_Customer_No_" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_bill_to_Name" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_customer_No_" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_description" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_fix_By_Date" type="xs:dateTime"/> 
<xs:element minOccurs="0" name="_fix_By_Time" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_fixed_Date" type="xs:dateTime"/> 
<xs:element minOccurs="0" name="_fixed_Time" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_name" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_no_" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_order_Date" type="xs:dateTime"/> 
<xs:element minOccurs="0" name="_order_Time" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_responded_Date" type="xs:dateTime"/> 
<xs:element minOccurs="0" name="_responded_Time" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_response_Date" type="xs:dateTime"/> 
<xs:element minOccurs="0" name="_response_Time" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_transaction_Status" nillable="true" type="xs:string"/> 
<xs:element minOccurs="0" name="_your_Reference" nillable="true" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
<xs:element name="serviceOrderCT" nillable="true" type="tns:serviceOrderCT"/> 
</xs:schema> 
</wsdl:types> 
<wsdl:message name="IMobileService_GetServiceOrders_InputMessage"> 
<wsdl:part name="parameters" element="tns:GetServiceOrders"/> 
</wsdl:message> 
<wsdl:message name="IMobileService_GetServiceOrders_OutputMessage"> 
<wsdl:part name="parameters" element="tns:GetServiceOrdersResponse"/> 
</wsdl:message> 
<wsdl:portType name="IMobileService"> 
<wsdl:operation name="GetServiceOrders"> 
<wsdl:input wsaw:Action="http://tempuri.org/IMobileService/GetServiceOrders" message="tns:IMobileService_GetServiceOrders_InputMessage"/> 
<wsdl:output wsaw:Action="http://tempuri.org/IMobileService/GetServiceOrdersResponse" message="tns:IMobileService_GetServiceOrders_OutputMessage"/> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="BasicHttpBinding_IMobileService" type="tns:IMobileService"> 
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="GetServiceOrders"> 
<soap:operation soapAction="http://tempuri.org/IMobileService/GetServiceOrders" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="MobileService"> 
<wsdl:port name="BasicHttpBinding_IMobileService" binding="tns:BasicHttpBinding_IMobileService"> 
<soap:address location="http://[IP Address There is no localhost]/MobileWebService/MobileWebService.MobileService.svc"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

Когда я запускаю этот код, я получите следующее XmlPullParserException: Неожиданный токен (позиция: ТЕКСТ сообщение об ошибке:

03-03 15:55:31.440 18414-18414/com.example.xxx.test I/art: Not late-enabling -Xcheck:jni (already on) 
03-03 15:55:31.544 18414-18414/com.example.xxx.test W/System: ClassLoader referenced unknown path: /data/app/com.example.xxx.test-1/lib/x86 
03-03 15:55:31.617 18414-18433/com.example.xxx.test D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
03-03 15:55:31.715 18414-18433/com.example.xxx.test I/OpenGLRenderer: Initialized EGL, version 1.4 
03-03 15:55:31.731 18414-18434/com.example.xxx.test I/System.out: Request::GetServiceOrders{} 
03-03 15:55:31.777 18414-18433/com.example.xxx.test W/EGL_emulation: eglSurfaceAttrib not implemented 
03-03 15:55:31.777 18414-18433/com.example.xxx.test W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad79fe60, error=EGL_SUCCESS 
03-03 15:55:31.816 18414-18434/com.example.xxx.test I/System.out: Testing 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT Bad [email protected]:12 in [email protected]) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at org.kxml2.io.KXmlParser.next(KXmlParser.java:432) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at org.kxml2.io.KXmlParser.next(KXmlParser.java:313) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2048) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at org.ksoap2.SoapEnvelope.parse(Unknown Source) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at org.ksoap2.transport.Transport.parseResponse(Unknown Source) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at org.ksoap2.transport.HttpTransportSE.call(Unknown Source) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at com.example.xxx.test.Test.WebServiceCallExample(Test.java:82) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at com.example.xxx.test.Test$SoapTask.doInBackground(Test.java:39) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at com.example.xxx.test.Test$SoapTask.doInBackground(Test.java:27) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at android.os.AsyncTask$2.call(AsyncTask.java:295) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
03-03 15:55:31.816 18414-18434/com.example.xxx.test W/System.err:  at java.lang.Thread.run(Thread.java:818) 
03-03 15:55:31.907 18414-18433/com.example.xxx.test W/EGL_emulation: eglSurfaceAttrib not implemented 
03-03 15:55:31.908 18414-18433/com.example.xxx.test W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad79ff00, error=EGL_SUCCESS 
03-03 15:55:32.065 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 7.988ms 
03-03 15:55:32.777 18414-18433/com.example.xxx.test E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab812650 
03-03 15:55:32.792 18414-18414/com.example.xxx.test I/Choreographer: Skipped 43 frames! The application may be doing too much work on its main thread. 
03-03 15:57:48.796 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 14.845ms 
03-03 16:11:41.066 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 12.014ms 
03-03 16:16:57.038 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 20.365ms 
03-03 16:25:56.319 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 22.178ms 
03-03 16:32:00.297 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 5.924ms 
03-03 16:32:41.884 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 11.291ms 
03-03 16:34:58.627 18414-18420/com.example.xxx.test W/art: Suspending all threads took: 22.906ms 

Я прокомментировал, какая из трех строк указала, что вам не нужно.

Это то, на что мне действительно нужна помощь, поэтому я был бы очень благодарен за любой вклад.

Спасибо.

P.S. ПОЖАЛУЙСТА не говорите мне «Посмотрите на это: (ссылка переполнения стека)», потому что я уже видел это, и я не могу связать его с моей проблемой.

ответ

0

Оказывается, проблема была, несмотря на то, что мой wsdl сказал, что это версия 1.2, я заменил конверт на мыло обратно на 1.1, и он работал нормально. Это строка, которую я изменил.

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

Теперь я могу подключиться к службе WCF.

NOBODY помогает мне!