0

I have a WCFService that returns sundry types of Data in this kind of a way:

[DataContract( Name="Amazing", NameSpace="http://schemas.myorganisation.com/DataContract1")]
Public class AmazingDto
{
    [DataMember( Order=0, IsRequired=true )]
    public string Name { get; set; }

    [DataMember( Order=0, IsRequired=true )]
    public bool IsAmazing { get; set; }

}

And then

[DataContract ( Name="GetAmazingListResponse", NameSpace="http://schemas.myorganisation.com/DataContract1")]
Public class GetAmazingListResponseDto
{
     [DataMember(Order=0, IsRequired-true, EmitDefaultValue=False)]
     public ICollection<AmazingDto> AmazingList{ get; set; }
}

Also

[DataContract(Name = "Response", Namespace = "http://schemas.myorganisation.com/DataContract1")]
public class ResponseDto<TData> : BaseResponseDto
{
    public ResponseDto();

    [DataMember(Order = 0, IsRequired = true)]
    public StatusDto Status { get; set; }

    [DataMember(Order = 1, IsRequired = false, EmitDefaultValue = false)]
    public TData Data { get; set; }
}

And then

public ResponseDto<GetAmazingListResponseDto> GetAmazingList()
{
      var response = new ResponseDto<GetAmazingListDto>
       {
            Status = new StatusDto { StatusResult = StatusResultEnum.Success },
            Data = new GetAmazingListResponseDto
                 {
                     AmazingList = new List<AmazingDto>
                      {
                           new AmazingDto { Name="Ponies", IsAmazing=true },
                           new AmazingDto { Name="Glenatron", IsAmazing=false }
                       }
                 }
       };
       return response;
}

Now when I make a call to that service using a tool like SoapUI I get exactly the response I might expect.

  <GetAmazingListResult xmlns:a="http://schemas.myorganisation.com/DataContract1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Status>
           <a:StatusResult>Success</a:StatusResult>
        </a:Status>
        <a:Data xmlns:b="http://schemas.myorganisation.com/DataContract1">
           <b:AmazingList>
              <b:Amazing>
                 <b:Name>Ponies</b:Name>
                 <b:IsAmazing>true</b:IsAmazing>
              </b:Amazing>
              <b:Amazing>
                 <b:Name>Glenatron</b:Name>
                 <b:IsAmazing>false</b:IsAmazing>
              </b:Amazing>
           </b:AmazingList>
        </a:Data>
     </GetAmazingListResult>

However, when I use Visual Studio 2010 to create a Service Reference and make a call like this:

var client= new FindoutAmazingnessServiceClient();
var response = client.GetAmazingList();

What I find is that response only has two properties, Status and ExtensionData. I have seen this described in other SE questions but the answer was always that something was missing a DataContract or DataMember on the data contracts. I definitely have those, so something else must be happening so that VS.Net can't see my classes. I have tried referencing the DTO library that contains these files and trying to configure the reference to match types with that library, but it makes no difference.

Where am I going wrong?

4

2 回答 2

1

只需将 [DataMember] 添加到您的数据成员。它解决了我的问题。

于 2015-08-14T09:14:31.157 回答
0

我找到的解决方案是,当我使用自己的 WCF 服务时,将接口导入我的客户端,然后使用ChannelFactory设置连接。这在我的场景中效果很好,但不能解决我提出的这个问题。

于 2013-06-13T14:35:03.247 回答