2012-03-17 2 views
1

내 응용 프로그램에서 웹 서비스를 호출하려고합니다. 내가 입력 한 후 잘 작동하지만 같은 문자열 또는 원시를 받아 웹 서비스 메서드를 호출하면 때 복잡한 객체를 허용하는 웹 서비스 메서드 호출 후 나는 다음과 같은 얻을 오류웹 서비스에 복잡한 객체 전달

org.apache.axis2.AxisFault: Unknow type {http://spec.com}specimen 
    at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:349) 
    at org.apache.axis2.databinding.utils.BeanUtil.processObject(BeanUtil.java:827) 
    at org.apache.axis2.databinding.utils.BeanUtil.ProcessElement(BeanUtil.java:746) 

I (내 경우에는 표본 클래스의) 다음입니다 : 내가 웹 서비스 탐색기에서 내 웹 서비스를 테스트하고 그 작업 fine.Here가 여기 내 웹 서비스

package com.spec; 

public class Spec { 

    public String sayHello(String name) // I can successfully invoke this 
    { 
     return "Have a great day " + name; 
    } 

    public String saveSpecimen(Specimen specimen) // Getting error for this 
    { 
     System.out.println("id: " + specimen.getId()); 
     System.out.println("name: " + specimen.getName()); 
     return "Specimend with id " + specimen.getId() + " is successfully saved"; 
    } 
} 

입니다 http://seesharpgears.blogspot.in/2010/10/ksoap-android-web-service-tutorial-with.html

나의 표본 클래스

입니다 활동에서 6,이
package com.ws; 

import java.util.Hashtable; 

import org.ksoap2.serialization.KvmSerializable; 
import org.ksoap2.serialization.PropertyInfo; 

public class Specimen implements KvmSerializable { 
    int id; 
    String name; 

    public Specimen() { 
    } 

    public Specimen(int idValue, String nameValue) { 
     id = idValue; 
     name = nameValue; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public Object getProperty(int arg0) { 
     if (arg0 == 0) 
      return id; 
     else 
      return name; 
    } 

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

    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo info) { 
     switch (arg0) { 
     case 0: 
      info.type = PropertyInfo.INTEGER_CLASS; 
      info.name = "id"; 
      break; 
     case 1: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "name"; 
      break; 
     default: 
      break; 
     } 
    } 

    public void setProperty(int arg0, Object value) { 
     switch (arg0) { 
     case 0: 
      id = Integer.parseInt(value.toString()); 
      break; 
     case 1: 
      name = value.toString(); 
      break; 
     } 
    } 
} 

발췌문

SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, 
       OPERATION_NAME); 

     Specimen specimen = new Specimen(); 
     specimen.setId(1); 
     specimen.setName("Test_Specimen"); 
     PropertyInfo info = new PropertyInfo(); 
     info.setName("specimen"); 
     info.setValue(specimen); 
     info.setType(specimen.getClass()); 
     request.addProperty(info); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
       SoapEnvelope.VER11); 
     envelope.setOutputSoapObject(request); 
     envelope.addMapping(WSDL_TARGET_NAMESPACE, "specimen",new Specimen().getClass()); 
     HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 
      httpTransport.call(SOAP_ACTION, envelope); 
      SoapObject response = (SoapObject)envelope.getResponse(); 
      Toast.makeText(getApplicationContext(),"Msg from web servce "  +    response.toString(),Toast.LENGTH_LONG).show(); 

나는 문제가 WSDL 파일 내 표본 복합 유형 선언이

<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" argetNamespace="http://spec.com/xsd"> 
<xs:complexType name="Specimen"> 
<xs:sequence> 
<xs:element minOccurs="0" name="id" type="xs:int"/> 
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/></xs:sequence></xs:complexType> 
</xs:schema> 

날 경우 알려 주시기 바랍니다 여기

envelope.addMapping(WSDL_TARGET_NAMESPACE, "specimen",new Specimen().getClass()); 

으로 생각 나는 실수를 저지르고있다.

감사합니다.

+0

대문자로 만드십시오 envelope.addMapping (WSDL_TARGET_NAMESPACE, "Specimen", 새로운 Specimen(). getClass()); 그것이 효과가 있는지보십시오. 나는 잘 모르겠다. – riship89

+0

@ hrishikeshp19 : 행운을 빌어 요. – xyz

+1

여기를 방문하셨습니까?> http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives? – OguzOzkeroglu

답변

0

많은 시도했지만 제대로 작동하지 못했습니다. 따라서 간단한 매개 변수로 업데이트 된 웹 서비스와 객체에있는 모든 속성을 전달했습니다.

1

이 시도 :

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
request.addProperty("Specimen", specimen); 
SoapSerializationEnvelope envelope = 
     new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.dotNet = true; 
envelope.setOutputSoapObject(request); 
envelope.addMapping("http://spec.com/xsd", "Specimen", new Specimen().getClass()); 

try { 
    HttpTransportSE transport = new HttpTransportSE(SOAP_ADDRESS); 
    transport.call(NAMESPACE + METHOD_NAME, envelope); 
    Object response = envelope.getResponse(); 
    String result = response.toString(); 
    /* make a toast ... */ 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

를가 작동하여 WSDL_TARGET_NAMESPACE, OPERATION_NAME 및 주소 문자열을 게시하지 않습니다.

+0

당신의 제안을 시도했지만'ArrayIndexOutofBoundExeption'을 얻지는 못했습니다. – xyz

+0

아마도 응답이 응답하는 방식으로 오류가 발생했습니다. 해당 회선을 변경하십시오. 나는 나머지는 괜찮다고 생각한다. –

+0

@enmarc : 나는'envelop.getResponse'가'arrayIndexOutofBoundException'을 초래할 것이라고 생각하지 않습니다. – xyz

관련 문제