End Google Ads 201810 - BS.net 01 -->
Hi Folks,
I have a question about the best way to design / redesign my software. I have a program that uses a web services to perform certain tasks. Each task is a different set of request / response classes on the server end and a general function call from the Main Hook. EG.
RequestObject req = new RequestObject("SomeVal");ResponseObject rsp = new ResponseObject(); rsp = WebServiceHook.Method1(RequestObject); //Returns ResponseObject
Each Method takes a different request object and returns a different type of response object.
As it stands i have a class for each of these methods, Each class has a public method Process() that does the interaction. I am trying to determine the best way to group all this code together using OO techniques without sacrificing functionality. I would like just one ProcessMethod in one class that will handle the interaction with the webservice for all the different web methods. So i would only call one ProcessMethod passing a switch of sorts that would define the relevant types and uniques strings that method requires. Some Sample code below:
[ComVisible(false)] private static InfoRequest infoReq = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD [ComVisible(false)] private static InfoResponse infoRsp = null; //TYPES WILL DIFFER IN EACH PROCESS METHOD //PARAM TYPES WILL DIFFER IN EACH PROCESS METHOD public static bool Process(INTERFACEREQUEST COMReq, out INTERFACERESPONSE COMRsp) { bool blnReturnVal = false; //Always the same CInfoRsp InfoRsp = new CInfoRsp(); //TYPES WILL DIFFER IN EACH PROCESS METHOD CInfoReq InfoReq = (CInfoReq)COMReq; //TYPES WILL DIFFER IN EACH PROCESS METHOD Globals.dtStart = DateTime.Now; //Always the same Globals.Log(Logger.LogLevel.Minimum, Logger.LogType.APIMethodEntryPoint, "SOME TEXT HERE", "AND HERE", InfoReq.SalePointID);//Always the same - Except for the Piece of Text try { Globals.TheService.Url = Settings.URL; //Always the same infoReq = new InfoRequest(); //TYPES WILL DIFFER IN EACH PROCESS METHOD infoRsp = new InfoResponse(); //TYPES WILL DIFFER IN EACH PROCESS METHOD SetRequest(InfoReq); //Set the PHS Request Object = to Our Values Passed from the COM Component CallWEBServiceMethod(); //Call the Web Service passing the appropriate arguments SetCOMResponseValues(InfoRsp); //Get the Info Response and Map it to Our InfoResponse Object COMRsp = InfoRsp; //Assign the Out Variable for COM blnReturnVal = AssignCOMResponse(InfoRsp); // Set the Return Value } catch (Exception ee) //Catch any Exception that might occur along the Way { //Ensure we set the Out Variable to NULL and the return Value to False, Log this Exception Too COMRsp = new CInfoRsp(ee); blnReturnVal = false; Globals.Log(Logger.LogLevel.All, Logger.LogType.APIMethodException, ee.ToString() + " " + ee.InnerException); } finally { InfoRsp = null; InfoReq = null; infoReq = null; infoRsp = null; GC.Collect(); } }
Is what i am trying to achieve possible or am i trying to over engineer this solution. It currently works i just find every time i have to add a new web method call i clone one of the existing classes and change the types in the processMethod and anywhere else that's needed. This is quite tedious and prone to bugs.
Thanks In Advance
مواقع النشر (المفضلة)