2013-07-23 1 views
2

jax-ws를 사용하여 간단한 웹 서비스를 만들 수 있습니다. 나는 안드로이드에서 그 webservice를 소비해야합니다. 나는이 오류 org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT [email protected]:1 in [email protected])있어 그 웹 서비스를 소비 할 때org.xmlpull.v1.XmlPullParserException 해결 방법 : 예기치 않은 유형 (위치 : END_DOCUMENT [email protected]의 @ 1 : 1)

내 WSDL 코드 :

<definitions targetNamespace="http://sample.jaxws.ws.blog.accrd.com/" name="SimpleWebServiceService"> 
<types> 
<xsd:schema> 
<xsd:import namespace="http://sample.jaxws.ws.blog.accrd.com/" schemaLocation="http://localhost:8080/SimpleWebService/SimpleWebService?xsd=1"/> 
</xsd:schema> 
</types> 
<message name="sayHello"><part name="parameters" element="tns:sayHello"/></message><message name="sayHelloResponse"> 
<part name="parameters" element="tns:sayHelloResponse"/> 
</message> 
<portType name="SimpleWebService"><operation name="sayHello"> 
<input wsam:Action="http://sample.jaxws.ws.blog.accrd.com/SimpleWebService/sayHelloRequest" message="tns:sayHello"/> 
<output wsam:Action="http://sample.jaxws.ws.blog.accrd.com/SimpleWebService/sayHelloResponse" message="tns:sayHelloResponse"/> 
</operation> 
</portType> 
<binding name="SimpleWebServicePortBinding" type="tns:SimpleWebService"> 
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="sayHello"> 
<soap12:operation soapAction=""/> 
<input> 
<soap12:body use="literal"/> 
</input> 
<output> 
<soap12:body use="literal"/> 
</output> 
</operation> 
</binding> 
<service name="SimpleWebServiceService"> 
<port name="SimpleWebServicePort" binding="tns:SimpleWebServicePortBinding"><soap12:address location="http://localhost:8080/SimpleWebService/SimpleWebService"/> 
</port> 
</service> 
</definitions> 

내 활동 :

public class MainActivity extends Activity { 


    public final static String URL ="http://localhost:8080/SimpleWebService/SimpleWebService?wsdl"; 
    public static final String NAMESPACE = "http://sample.jaxws.ws.blog.accrd.com/"; 
    public static final String SOAP_ACTION = "http://sample.jaxws.ws.blog.accrd.com/sayHello"; 
    private static final String METHOD = "sayHello"; 




@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    final TextView tv = (TextView) findViewById(R.id.txt1); 
    Button btn = (Button) findViewById(R.id.button1); 

    btn.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      SoapObject request = new SoapObject(NAMESPACE, METHOD); 
      Customer cu = new Customer(); 

      cu.setFirstName("FirstName"); 
      cu.setLastName("LastName"); 
      PropertyInfo propInfo = new PropertyInfo(); 
      propInfo.name = "arg0"; 
      propInfo.type = Customer.class; 
      request.addProperty(propInfo, cu); 




      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER12); 




      envelope.setOutputSoapObject(request); 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 


      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       Log.d("Error", "Finished"); 

       SoapObject response=(SoapObject)envelope.bodyIn; 



       tv.setText(response.toString()); 

      } catch (Exception e) { 
       Log.d("Error", e.toString()); 

      } 

     } 
    }); 

}} 

내 Customer.java

public class Customer implements KvmSerializable { 

    private String firstName; 

    private String lastName; 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    public String getLastName() { 
     return lastName; 
    } 

    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    @Override 
    public Object getProperty(int arg0) { 
     Object object = null; 
     switch (arg0) { 

     case 0: 
      object = this.firstName; 
      break; 
     case 1: 
      object = this.lastName; 
      break; 

     } 
     return object; 

    } 

    @Override 
    public int getPropertyCount() { 
     // TODO Auto-generated method stub 
     return 2; 
    } 

    @Override 
    public void getPropertyInfo(int arg0, Hashtable arg1, 
      PropertyInfo propertyInfo) { 
     switch (arg0) { 
     case 0: 
      propertyInfo.name = "firstName"; 
      propertyInfo.type = PropertyInfo.STRING_CLASS; 
      break; 

     case 1: 
      propertyInfo.name = "lastName"; 
      propertyInfo.type = PropertyInfo.STRING_CLASS; 
      break; 

     } 

    } 

    @Override 
    public void setProperty(int arg0, Object object) { 
     switch (arg0) { 

     case 0: 
      this.firstName = object.toString(); 
      break; 

     case 1: 
      this.lastName = object.toString(); 
      break; 

     } 

    } 

} 

@ BindingType을 사용할 때 jax-ws webservice에서 soap1.1이 올바른 응답을 얻습니다. 하지만 @ BindingType 내 jax-ws webservice soap1.2 사용할 때이 오류 org.xmlpull.v1.XmlPullParserException : 예기치 않은 형식 (위치 : END_DOCUMENT [email protected] null @ 1 : 1).

어떻게이 문제를 해결할 수 있습니까?

+0

또한 미래에 그것은 훨씬 쉽게 :) –

+1

오류 라인은 androidHttpTransport, 당신의 네트워크 작업을 처리 할 수 ​​RoboSpice 같은 라이브러리를 사용하는 것이 좋습니다, 디버깅 및이 오류가 발생 어떤 라인을 찾아주십시오. 호출 (SOAP_ACTION, envelope); – jeevamuthu

+0

나는 오류가 나타나면 응답이 비어 있거나 봉투에 맞지 않는다는 것을 확신 할 수 있습니까? –

답변

-2

@jeevamuthu와 이야기 한 후 문제는 ksoap 라이브러리를 빌드 경로에 추가하고 코드를 약간 수정해야한다는 것이 었습니다. 비슷한 문제가있는 경우 @jeevamuthu에게이 문제를 해결하는 방법에 대한 정보를 문의하십시오.

PropertyInfo propInfo = new PropertyInfo(); 
propInfo.name = "arg0"; propInfo.value=cu; 
propInfo.type = Customer.class; 
request.addProperty(propInfo); 
관련 문제