How can I control the name of generic WCF return types?

后端 未结 3 2052
遇见更好的自我
遇见更好的自我 2020-12-06 02:39

I\'ve got a WCF Web Service method whose prototype is:

[OperationContract]
Response> GetCustomers();

When I add

相关标签:
3条回答
  • 2020-12-06 03:28

    Please try this:

    [OperationContract]
    [return: MessageParameter(Name="YOURNAME")]
    Response<List<Customer>> GetCustomers();
    
    0 讨论(0)
  • 2020-12-06 03:30

    You can define your own name in the DataContract attribute like this:

    [DataContract(Name = "ResponseOf{0}")]
    public class Response<T>
    

    Note that in your example the {0} will be replaced and your proxy reference type will be ResponseOfArrayOfCustomer.

    More info here: WCF: Serialization and Generics

    0 讨论(0)
  • 2020-12-06 03:41

    Yes. The OperationContractAttribute takes a parameter called Name. You could specify it like this:

    [OperationContract(Name = "NameGoesHere")]
    Response<List<Customer>> GetCustomers();
    
    0 讨论(0)
提交回复
热议问题