WCF服务如何从方法返回多个响应 [英] How WCF Service returns multiple response from Method
问题描述
大家好,
我有一个WCF服务和一个在服务中名为public GetDataUsingMethodList()的单一方法.当它返回单一响应时,它可以正常工作.
但是我想返回多个响应,即List和String都来自方法GetDataUsingMethodList().
请帮助我.
Hi guys,
Hi I have one WCF service and one single method named public GetDataUsingMethodList() in the service.It''s working fine when it''s return single response.
But i want to return multiple response i.e. List and String both from Method GetDataUsingMethodList().
Please help me on this.
推荐答案
使用DataContract
.
例如:
UseDataContract
.
For Example:
[DataContract]
public class Result
{
[DataMember]
public List<int> ListOutPut { get;set;}
[DataMember]
public String StringOutPut { get;set;}
}
现在,将其用作合同中的返回类型,即在服务类及其接口中.
例如:
Now, use this as the return type in your contract, i.e. both in service class and its interface.
For example:
public interface IService
{
Result GetDataUsingMethodList();
}
public class Service : IService
{
public Result GetDataUsingMethodList()
{
// create the result and return it.
}
}
这样,您可以在输出中实现多种类型.
This way, you can achieve multiple types within the output.
这篇关于WCF服务如何从方法返回多个响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!