Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将序列化对象从android传递到C#web服务_C#_Android_Web Services_Serialization_Ksoap2 - Fatal编程技术网

无法将序列化对象从android传递到C#web服务

无法将序列化对象从android传递到C#web服务,c#,android,web-services,serialization,ksoap2,C#,Android,Web Services,Serialization,Ksoap2,我想通过ksoap2将一个对象从android应用程序发送到c#web服务。 webService方法获取ReceptionCommitteem对象。 此对象在C#webService中定义为: [Serializable] [XmlType(TypeName = "RCI")] public class ReceptionCommitItem { [XmlAttribute(AttributeName = "Id")] public int ReceptionNumber {

我想通过ksoap2将一个对象从android应用程序发送到c#web服务。 webService方法获取ReceptionCommitteem对象。 此对象在C#webService中定义为:

[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>();
    }
}

如果有人能帮助我,我将不胜感激。Ksoap不支持自定义对象的自动序列化。您应该使用
SoapObject
PropertyInfo
类按属性序列化对象属性。或者,您可以通过实现
KvmSerializable
接口使类可序列化。参见示例。

我检查了ksoap2的src(org/ksoap2/serialization/)中的SoapSerializationEnvelope类,发现我也应该序列化ReceptionCommitteem的Enum属性

谢谢,但正如我在代码中提到的,我使用了SoapObject和PropertyInfo类。我也尝试了KvmSerializable,但没有解决。您可以将它与自定义的
ReceptionCommitteem
类一起使用。但是KSoap在默认情况下只能序列化一些基本类型(以及实现
KvmSerializable
Marshal
接口的类型)。您可以实现其中一个接口,也可以编写对象的每个属性。我检查了ksoap2的src(org/ksoap2/serialization/)中的SoapSerializationEnvelope类,发现我也应该序列化ReceptionCommitteem的Enum属性。
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>();
}
}
<?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>
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;
}
**EXCEPTION NAME:  java.lang.RuntimeException: Cannot serialize: ReceptionCommitItem : org.package.bean.ReceptionCommitItem@46022360**
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)