Skip to main content
deleted 69 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

OO Design in C# Web service performing different tasks

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.

As it stands i, I have a class for each of these methods, Each. Each class has a public method Process()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 ProcessMethodProcessMethod in one class that will handle the interaction with the webserviceweb service for all the different web methods.

From reading about the OO patterns, it would appear the one iI need to use is the Abstractabstract factory pattern with the adapter and strategy pattern thrown in too.

SO Question about my design so far,Am I am wondering if i am going about this the right way?

I have a COM Library created in C#, with COMVisibleCOMVisible set to true. This library talks to a 3rd party WebServiceWebService calling various methods depending on the task at hand. For each RequestRequest / ResponseResponse class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application.

So with that in my iI have added a C# project to the solution to test this code, see test method below:

The link class looks like so at the moment be, but will have all the methods created once the design is correct:

Each DoMethod(N)DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethodsDoMethods. The key differences between the methods is the Param Types Passed in and the Method1Method1 (Method1RequestMethod1Request/Method1ResponseMethod1Response) type will vary depending on the webmethod to be called.

Class Method1Method1 (There will be one of these for every method I need to implement on the WebServiceWebService) looks like so:

The class (WebServiceInterfaceBridgeWebServiceInterfaceBridge) that all Method(N)Method(N) classes will inherit from is shown below:

And finally, here is the class that actually calls the Web service that the WebServiceBridgeWebServiceBridge Class inherits from:

I have left out my internal classes for marshaling the Req/Rsp's, they are just classes with Member Vars and Get/Set's.

So basically before i carry on with my design I am wondering from an OO point of view if I am approaching this task inhave left out my internal classes for marshaling the right way or if what I am doing is overkillReq/Rsp's, they are just classes with Member Vars and could be greatly simplified?Get/Sets.

TIABefore I carry on with my design, I am wondering, from an OO point of view, if I am approaching this task in the right way or if what I am doing is overkill and could be greatly simplified?

OO Design in C#

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.

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.

From reading about the OO patterns, it would appear the one i need to use is the Abstract factory pattern with the adapter and strategy pattern thrown in too.

SO Question about my design so far, I am wondering if i am going about this the right way?

I have a COM Library created in C#, with COMVisible set to true. This library talks to a 3rd party WebService calling various methods depending on the task at hand. For each Request / Response class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application.

So with that in my i have added a C# project to the solution to test this code, see test method below:

The link class looks like so at the moment be but will have all the methods created once the design is correct:

Each DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethods. The key differences between the methods is the Param Types Passed in and the Method1 (Method1Request/Method1Response) type will vary depending on the webmethod to be called.

Class Method1 (There will be one of these for every method I need to implement on the WebService) looks like so:

The class (WebServiceInterfaceBridge) that all Method(N) classes will inherit from is shown below:

And finally here is the class that actually calls the Web service that the WebServiceBridge Class inherits from:

I have left out my internal classes for marshaling the Req/Rsp's, they are just classes with Member Vars and Get/Set's.

So basically before i carry on with my design I am wondering from an OO point of view if I am approaching this task in the right way or if what I am doing is overkill and could be greatly simplified?

TIA

Web service performing different tasks

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.

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 web service for all the different web methods.

From reading about the OO patterns, it would appear the one I need to use is the abstract factory pattern with the adapter and strategy pattern thrown in too.

Am I going about this the right way?

I have a COM Library created in C#, with COMVisible set to true. This library talks to a 3rd party WebService calling various methods depending on the task at hand. For each Request / Response class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application.

I have added a C# project to the solution to test this code, see test method below:

The link class looks like so at the moment, but will have all the methods created once the design is correct:

Each DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethods. The key differences between the methods is the Param Types Passed in and the Method1 (Method1Request/Method1Response) type will vary depending on the webmethod to be called.

Class Method1 (There will be one of these for every method I need to implement on the WebService) looks like so:

The class (WebServiceInterfaceBridge) that all Method(N) classes will inherit from is shown below:

And finally, here is the class that actually calls the Web service that the WebServiceBridge Class inherits from:

I have left out my internal classes for marshaling the Req/Rsp's, they are just classes with Member Vars and Get/Sets.

Before I carry on with my design, I am wondering, from an OO point of view, if I am approaching this task in the right way or if what I am doing is overkill and could be greatly simplified?

Source Link

OO Design in C#

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.

From reading about the OO patterns, it would appear the one i need to use is the Abstract factory pattern with the adapter and strategy pattern thrown in too.

SO Question about my design so far, I am wondering if i am going about this the right way?

I have a COM Library created in C#, with COMVisible set to true. This library talks to a 3rd party WebService calling various methods depending on the task at hand. For each Request / Response class exposed by the 3rd party DLL I have a Request / Response Pair (Class and Interface) to Marshal variables specifically for a VC6 application.

Mainly using:

MarshalAs(UnmanagedType.LPStr)]

So with that in my i have added a C# project to the solution to test this code, see test method below:

static void Main(string[] args)
        {
            ICOMReq iReq = new CCOMReq();
            ICOMRsp iRsp = new CCOMRsp();
            Link l = new Link();

            iReq.Date_Time = DateTime.UtcNow;
            iReq.Var2 = "1023758145865";

            l.DoMethod1(iReq, out iRsp);

            //Handle COM Response here
        }

The link class looks like so at the moment be but will have all the methods created once the design is correct:

public class Link
    {
        public bool DoMethod1(ICOMReq _COMReq, out ICOMRsp COMRsp)
        {
            Method1 WebServiceMethod = new Method1(new Method1Request(), new Method1Response(), (CCOMReq)_COMReq, new CCOMRsp());
            WebServiceMethod.Process();

            //Just test code at the moment
            COMRsp = null;
            return true;
        }
    }

Each DoMethod(N) that will be in the link class will look the same performing its task with identical code to the other DoMethods. The key differences between the methods is the Param Types Passed in and the Method1 (Method1Request/Method1Response) type will vary depending on the webmethod to be called.

Class Method1 (There will be one of these for every method I need to implement on the WebService) looks like so:

public class Method1 : WebServiceInterfaceBridge<Method1Request, Method1Response, ICOMReq, ICOMRsp>
{
    public Method1(Method1Request WEB_Req, Method1Response WEB_Rsp, CCOMReq COM_Req, ICOMRsp COM_Rsp)
        : base(WEB_Req, WEB_Rsp, CBE_Req, CBE_Rsp) 
    {
        WEB_Req.SOME_DATE_TIME = COM_Req.Date_Time;
    }

    public new void Process()
    {
        base.Process();
    }

    public override void LOG()
    {
        Console.WriteLine(this.WebMethod_Request.MEMBER_VAR_HERE);
    }

    //There will be additional methods here in the end as well as a mapping method to convert the WEBMethodResponse to a COMResponse and pass it back to the caller
}

The class (WebServiceInterfaceBridge) that all Method(N) classes will inherit from is shown below:

public abstract class WebServiceInterfaceBridge <T,U,V,W> : WebServiceInterface
    where T : class 
    where U : class
    where V : class
    where W : class
{
    protected T WebMethod_Request;
    protected U WebMethod_Response;
    protected V COM_Request;
    protected W COM_Response;

    public WebServiceInterfaceBridge(T tPHSReq, U uPHSRsp, V vCBEReq, W wCBERsp)
    {
        WebMethod_Request = tPHSReq;
        WebMethod_Response = uPHSRsp;
        COM_Request = vCBEReq;
        COM_Response = wCBERsp;
    }

    public abstract void LOG();

    public void CallWebServiceMethod()
    {
        WebMethod_Response = CallWebMethod<T, U>(WebMethod_Request);
    }

    public void Process()
    {
        LOG();
        CallWebServiceMethod();
    }
}

And finally here is the class that actually calls the Web service that the WebServiceBridge Class inherits from:

public class WebServiceInterface
    {
        private ServiceClient WEBSVC = new ServiceClient();

        public U CallWebMethod<T, U>(T tRequest) 
            where T:class 
            where U:class
        {
            if (tRequest.GetType() == typeof(Method2Request))
            {
                Method2Request Req = (Method2Request)(object)tRequest;
                Method2Response Rsp = WEBSVC.Method2(Req);
                return (U)(object)Rsp;
            }
            else if (tRequest.GetType() == typeof(Method1Request))
            {
                Method1Request Req = (Method1Request)(object)tRequest;
                Method1Response Rsp = WEBSVC.Method1(Req);
                return (U)(object)Rsp;
            }
            else
            {
                throw new NullReferenceException();
            }
        }
    }

I have left out my internal classes for marshaling the Req/Rsp's, they are just classes with Member Vars and Get/Set's.

So basically before i carry on with my design I am wondering from an OO point of view if I am approaching this task in the right way or if what I am doing is overkill and could be greatly simplified?

TIA