2013-10-10 4 views
0

ksoap2를 통해 Android App에서 C# Web 서비스로 객체를 보내려고합니다. webService 메서드는 ReceptionCommitItem 개체를 가져옵니다.Android에서 Serialized 객체를 C# Web Service로 전달할 수 없습니다.

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <CommitSingleReceiption xmlns="http://samplegroup.ir/"> 
     <item Id="int" St="-2 or -1 or 0 or 1 or 2 or 3 " PRN="string" SN="string" BId="int" PgId="int" SgId="int" MId="int" SId="int" Ad="string" HF="boolean" CR="boolean" CP="Nothing or Status or PartRequestNumber or ModelTree or Serial or Address"> 
     <FactorParts> 
      <FP Id="int" Q="unsignedByte" W="boolean" P="int" /> 
      <FP Id="int" Q="unsignedByte" W="boolean" P="int" /> 
     </FactorParts> 
     <FactorServices> 
      <FS Id="int" IF="boolean" W="boolean" Q="unsignedByte" SP="int" TP="int" G="unsignedByte" /> 
      <FS Id="int" IF="boolean" W="boolean" Q="unsignedByte" SP="int" TP="int" G="unsignedByte" /> 
     </FactorServices> 
     </item>  
    </CommitSingleReceiption> 
    </soap:Body> 
</soap:Envelope> 

I : 다음

import java.io.Serializable; 
import java.util.ArrayList; 
import java.util.Hashtable; 
import java.util.List; 
import java.util.Vector; 

import org.ayriksoft.entekhab.util.Enum.ReceptionChanges; 
import org.ayriksoft.entekhab.util.Enum.ReceptionStatuses; 
import org.ksoap2.serialization.KvmSerializable; 
import org.ksoap2.serialization.PropertyInfo; 
import org.simpleframework.xml.Attribute; 
import org.simpleframework.xml.Element; 


@Element(name = "item") 
public class ReceptionCommitItem implements Serializable { 

    @Attribute(name = "Id") 

public int ReceptionNumber; 

@Attribute(name = "St", required = false) 
public ReceptionStatuses NewStatus; 

@Attribute(name = "PRN", required = false) 
public String PartRequestNumber; 

@Attribute(name = "SN", required = false) 
public String SerialNumber; 

@Attribute(name = "BId") 
public int BrandId; 

@Attribute(name = "PgId") 
public int ProductGroupId; 

@Attribute(name = "SgId") 
public int SubgroupId; 

@Attribute(name = "MId") 
public int ModelId; 

@Attribute(name = "SId") 
public int SeriId; 

@Attribute(name = "Ad", required = false) 
public String Address; 

@Attribute(name = "HF") 
public boolean HasFactorData; 

@Attribute(name = "CR") 
public boolean CommitReception; 

@Attribute(name = "CP") 
public ReceptionChanges ChangedProperties; 

@Attribute(required = false) 
public boolean HasConfilict; 

public List<FactorPart> FactorParts; 

public List<FactorService> FactorServices; 


public int getReceptionNumber() { 
    return ReceptionNumber; 
} 

public void setReceptionNumber(int receptionNumber) { 
    ReceptionNumber = receptionNumber; 
} 

public ReceptionStatuses getNewStatus() { 
    return NewStatus; 
} 

public void setNewStatus(ReceptionStatuses newStatus) { 
    NewStatus = newStatus; 
} 

public String getPartRequestNumber() { 
    return PartRequestNumber; 
} 

public void setPartRequestNumber(String partRequestNumber) { 
    PartRequestNumber = partRequestNumber; 
} 

public String getSerialNumber() { 
    return SerialNumber; 
} 

public void setSerialNumber(String serialNumber) { 
    SerialNumber = serialNumber; 
} 

public int getBrandId() { 
    return BrandId; 
} 

public void setBrandId(int brandId) { 
    BrandId = brandId; 
} 

public int getProductGroupId() { 
    return ProductGroupId; 
} 

public void setProductGroupId(int productGroupId) { 
    ProductGroupId = productGroupId; 
} 

public int getSubgroupId() { 
    return SubgroupId; 
} 

public void setSubgroupId(int subgroupId) { 
    SubgroupId = subgroupId; 
} 

public int getModelId() { 
    return ModelId; 
} 

public void setModelId(int modelId) { 
    ModelId = modelId; 
} 

public int getSeriId() { 
    return SeriId; 
} 

public void setSeriId(int seriId) { 
    SeriId = seriId; 
} 

public String getAddress() { 
    return Address; 
} 

public void setAddress(String address) { 
    Address = address; 
} 

public boolean isHasFactorData() { 
    return HasFactorData; 
} 

public void setHasFactorData(boolean hasFactorData) { 
    HasFactorData = hasFactorData; 
} 

public boolean isCommitReception() { 
    return CommitReception; 
} 

public void setCommitReception(boolean commitReception) { 
    CommitReception = commitReception; 
} 

public ReceptionChanges getChangedProperties() { 
    return ChangedProperties; 
} 

public void setChangedProperties(ReceptionChanges changedProperties) { 
    ChangedProperties = changedProperties; 
} 

public boolean isHasConfilict() { 
    return HasConfilict; 
} 

public void setHasConfilict(boolean hasConfilict) { 
    HasConfilict = hasConfilict; 
} 

public List<FactorPart> getFactorParts() { 
    return FactorParts; 
} 

public void setFactorParts(List<FactorPart> factorParts) { 
    FactorParts = factorParts; 
} 

public List<FactorService> getFactorServices() { 
    return FactorServices; 
} 

public void setFactorServices(List<FactorService> factorServices) { 
    FactorServices = factorServices; 
} 

public ReceptionCommitItem() { 
    this.CommitReception = true; 
    this.HasFactorData = false; 
    this.ChangedProperties = ReceptionChanges.Nothing; 
    FactorParts=new ArrayList<FactorPart>(); 
    FactorServices=new ArrayList<FactorService>(); 
} 
} 

은 샘플 SOAP 1.1 요청입니다 : 불어로 C#을 웹 서비스에 정의 된 이 객체 : 자바에서 불어로

[Serializable] 
[XmlType(TypeName = "RCI")] 
public class ReceptionCommitItem 
{ 
    [XmlAttribute(AttributeName = "Id")] 
    public int ReceptionNumber { get; set; } 
    [XmlAttribute(AttributeName = "St")] 
    public ReceptionStatuses NewStatus { get; set; } 
    [XmlAttribute(AttributeName = "PRN")] 
    public string PartRequestNumber { get; set; } 
    [XmlAttribute(AttributeName = "SN")] 
    public string SerialNumber { get; set; } 
    [XmlAttribute(AttributeName = "BId")] 
    public int BrandId { get; set; } 
    [XmlAttribute(AttributeName = "PgId")] 
    public int ProductGroupId { get; set; } 
    [XmlAttribute(AttributeName = "SgId")] 
    public int SubgroupId { get; set; } 
    [XmlAttribute(AttributeName = "MId")] 
    public int ModelId { get; set; } 
    [XmlAttribute(AttributeName = "SId")] 
    public int SeriId { get; set; } 

    [XmlAttribute(AttributeName = "Ad")] 
    public string Address { get; set; } 

    [XmlAttribute(AttributeName = "HF")] 
    public bool HasFactorData { get; set; } 

    [XmlAttribute(AttributeName = "CR")] 
    public bool CommitReception { get; set; } 

    [XmlAttribute(AttributeName = "CP")] 
    public ReceptionChanges ChangedProperties { get; set; } 

    [XmlIgnore] 
    public bool HasConfilict; 

    public List<FactorPart> FactorParts { get; set; } 
    public List<FactorService> FactorServices { get; set; } 

    public ReceptionCommitItem() 
    { 
     this.CommitReception = true; 
     this.HasFactorData = false; 
     this.ChangedProperties=ReceptionChanges.Nothing; 
     FactorParts=new List<FactorPart>(); 
     FactorServices=new List<FactorService>(); 
    } 
} 

나는이 클래스를 구현 코드에서 ksoap2의 ReServiceCommitItem을 webService로 보냈습니다.

OPERATION_NAME = webServiceMethodName; 
SOAP_ACTION = WSDL_TARGET_NAMESPACE + OPERATION_NAME; 
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, 
       OPERATION_NAME); 

PropertyInfo pi = new PropertyInfo(); 
pi.setName("ReceptionCommitItem"); 
pi.setValue((ReceptionCommitItem) itemValue); 
pi.setType(new ReceptionCommitItem().getClass()); 
request.addProperty("item", pi); 

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);// running 1.1 
soapEnvelope.dotNet = true; 
soapEnvelope.setOutputSoapObject(request); 
soapEnvelope.addMapping(WSDL_TARGET_NAMESPACE, "ReceptionCommitItem", 
     new ReceptionCommitItem().getClass()); 

HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 
try { 
    httpTransport.debug = true; 
    httpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 
    httpTransport.call(SOAP_ACTION, soapEnvelope); 
} catch (Exception e) { 
    throw e; 
} 

앱을 실행할 때 httpTransport.call (SOAP_ACTION, soapEnvelope);

**EXCEPTION NAME: java.lang.RuntimeException: Cannot serialize: ReceptionCommitItem : [email protected]** 
org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:679) 
org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:663) 
org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:632) 
org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:616) 
org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:673) 
org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:597) 
org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192) 
org.ksoap2.transport.Transport.createRequestData(Transport.java:101) 
org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114) 
org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90) 

어느 날

답변

0

나는 ksoap2의 SRC에 SoapSerializationEnvelope 클래스를 확인 (조직/ksoap2/직렬화 /) 그리고 난 내가 너무

1

Ksoap 사용자 정의 개체를 자동으로 직렬화를 지원하지 않습니다 도와 주면 내가 감사합니다 : 예외가 발생합니다. SoapObjectPropertyInfo 클래스를 사용하여 속성별로 객체 속성을 serialize해야합니다. 또는 KvmSerializable 인터페이스를 구현하여 클래스를 직렬화 할 수 있습니다. 예를 들어 this tutorial을 참조하십시오.

+0

감사합니다 ReceptionCommitItem의 열거 속성을 직렬화 것을 발견,하지만 난 내 코드에서 언급 한 바와 같이 나는 SoapObject 및 PropertyInfo 클래스를 사용 . 그리고 KvmSerializable [이 튜토리얼] (http://seesharpgears.blogspot.in/2010/10/ksoap-android-web-service-tutorial-with.html)도 시도했지만 해결되지 않았습니다. – Ghorbani

+0

커스텀'ReceptionCommitItem' 클래스와 함께 사용하십시오. 그러나 KSoap은 기본적으로 일부 기본 유형 (및'KvmSerializable' 또는'Marshal' 인터페이스를 구현하는 유형) 만 직렬화 할 수 있습니다. 이 인터페이스 중 하나를 구현하거나 객체의 각 속성을 작성해야합니다. – esentsov

+0

ksoap2의 src (org/ksoap2/serialization /)에서 SoapSerializationEnvelope 클래스를 검사했는데 ReceptionCommitItem의 Enum 속성도 직렬화해야한다는 것을 알았습니다. – Ghorbani

관련 문제