【发布时间】:2011-03-23 23:47:37
【问题描述】:
我有一个 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);
我遇到的问题是当我使用“添加服务引用”使用此服务时,wsdl 包含以下内容:
<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.Idk__BackingField、person.FirstNamek_BackingField 等,而不是 person.Id 和 person.FirstName。
我应该怎么做才能获得我在 WCF 服务端定义的确切类型?我在 PersonDTO 上使用 Serializable 属性,因为该服务需要与 java 互操作。我正在使用 .NET Framework 4.0、C#、Visual Studio 2010、Win XP SP3。 WCF 服务公开 http 端点并使用 basicHttpBinding。
【问题讨论】: