如何为不同的类方法调用创建一般响应。 [英] How to create a generic response for different class method call.

查看:70
本文介绍了如何为不同的类方法调用创建一般响应。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个WCF服务,当我们使用这个服务并调用我想要返回一般响应消息的任何方法时,它有许多类和许多方法,如GetCustomer,SaveCustomer,SaveTransaction等。例如如果我调用SaveCustomer然后在我的响应中我想发送responseCode = SUC(它的请求是否成功来了)result = Accepted,responseMessage =客户数据保存所以我创建了类似打击:

公共字符串结果{get;组; }

公共字符串responseCode {get;组; }

public string responseMessage {get;组;
并且想要返回该客户或事务对象,如果客户对象进入请求,那么我的上面的类对象加上客户那个对象,如果事务对象来了我的上面的类对象加上那个trasaction对象。还有很多其他课程。以及所有方法的输出类型应该是什么。

谢谢



我尝试了什么:



公共类clsBFCAPIResponse

{

公共字符串结果{get;组; }

公共字符串responseCode {get;组; }

public string responseMessage {get;组; }

}

I am creating a WCF service, which has many classes and many methods like GetCustomer, SaveCustomer, SaveTransaction etc. when we consume this service and call any method i want to return a generic response message. e.g. if i call SaveCustomer then in my response i want to send responseCode=SUC (its for request is successfuly came or not) result=Accepted, responseMessage="Customer data saved" so i created class like blow:
public string result { get; set; }
public string responseCode { get; set; }
public string responseMessage { get; set; }
and want to return that customer or transaction object also, if customer object came in request then my above class object plus customer that object if transaction object came then my above class object plus that trasaction object. there are many other classes also. and what should the output type of that all methods.
thanks

What I have tried:

public class clsBFCAPIResponse
{
public string result { get; set; }
public string responseCode { get; set; }
public string responseMessage { get; set; }
}

推荐答案

创建一个复杂的类并将这些类的对象添加为属性。然后实例化这个复杂类的对象并通过赋值来返回它。
Make a complex class and add objects of those classes as properties. Then instantiate object of this complex class and return that by assigning values.


你可以为每个响应类型创建响应类,让响应类继承clsBFCAPIResponse

例如class CustomerResponse:clsBFCAPIResponse {

Customer cust {get; set;}

}

class TransactionResponse:clsBFCAPIResponse {

Transaction trans {get;设置;}

}

这样每个响应都会有特定的类型。
You can make response class for each response type and let the response class inherit from clsBFCAPIResponse
e.g. class CustomerResponse: clsBFCAPIResponse{
Customer cust {get; set;}
}
class TransactionResponse: clsBFCAPIResponse{
Transaction trans {get; set;}
}
Such that each response will have it's specific type.


这篇关于如何为不同的类方法调用创建一般响应。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆