代码之家  ›  专栏  ›  技术社区  ›  KrishHari

使用自动属性标记类型会在WCF客户端代理代码上将生成的字段作为成员

  •  1
  • KrishHari  · 技术社区  · 16 年前

    我有一个DTO类型声明如下:

    [Serializable]
    public class PersonDTO
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    

    我有一个WCF服务,其运营合同如下:

    [OperationContract]
    public PersonDTO GetPerson(int id);
    

    <xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Test.DTO">
    −
       <xs:complexType name="PersonDTO">
    −
          <xs:sequence>
              <xs:element name="_x003C_Id_x003E_k__BackingField" nillable="true" type="xs:int"/>
              <xs:element name="_x003C_FirstName_x003E_k__BackingField" nillable="true" type="xs:string"/>
              <xs:element name="_x003C_LastName_x003E_k__BackingField" nillable="true" type="xs:string"/>
          </xs:sequence>
       </xs:complexType>
       <xs:element name="IVQueueDTO" nillable="true" type="tns:IVQueueDTO"/>
    </xs:schema>
    

    当我尝试在WCF客户机上引用时,不是获取person.Id和person.FirstName,而是获取person.Idk\u BackingField、person.FirstNamek\u BackingField等。

    2 回复  |  直到 16 年前
        1
  •  2
  •   Jerod Houghtelling    16 年前

    你试过使用DataContact和DataMember属性而不是Serializable吗?我相信这仍然会为您提供一个Java可以访问的可序列化对象。