Click here to Skip to main content
15,915,019 members
Home / Discussions / C#
   

C#

 
GeneralRe: Application Settings Pin
Eddy Vluggen23-Jul-13 0:29
professionalEddy Vluggen23-Jul-13 0:29 
QuestionResponsive UI - WPF with Properties Pin
SynergiAios22-Jul-13 15:09
SynergiAios22-Jul-13 15:09 
AnswerRe: Responsive UI - WPF with Properties Pin
Dave Kreskowiak22-Jul-13 16:32
mveDave Kreskowiak22-Jul-13 16:32 
GeneralRe: Responsive UI - WPF with Properties Pin
SynergiAios23-Jul-13 0:18
SynergiAios23-Jul-13 0:18 
QuestionOO Design for Specifc Problem Pin
KeithF22-Jul-13 6:17
KeithF22-Jul-13 6:17 
AnswerRe: OO Design for Specifc Problem Pin
KeithF22-Jul-13 21:41
KeithF22-Jul-13 21:41 
AnswerRe: OO Design for Specifc Problem Pin
Eddy Vluggen23-Jul-13 0:30
professionalEddy Vluggen23-Jul-13 0:30 
GeneralRe: OO Design for Specifc Problem Pin
KeithF30-Jul-13 22:49
KeithF30-Jul-13 22:49 
Folks,

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:
C#
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:

C#
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:

C#
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:

C#
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:

C#
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:

C#
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
QuestionMicrosoft Expression Encoder with IIS Live Smooth Streaming Issue Pin
Member 1003572121-Jul-13 21:46
Member 1003572121-Jul-13 21:46 
AnswerRe: Microsoft Expression Encoder with IIS Live Smooth Streaming Issue Pin
Dave Kreskowiak22-Jul-13 1:46
mveDave Kreskowiak22-Jul-13 1:46 
QuestionGetGuiThreadInfo can not get the caret's position Pin
goldli8820-Jul-13 23:12
goldli8820-Jul-13 23:12 
QuestionHow to Create Dynamic Buttons With Students Roll No. on It From Database Pin
jackspero1820-Jul-13 1:38
jackspero1820-Jul-13 1:38 
AnswerRe: How to Create Dynamic Buttons With Students Roll No. on It From Database Pin
Garth J Lancaster20-Jul-13 2:05
professionalGarth J Lancaster20-Jul-13 2:05 
QuestionC# unmanage DLL export Pin
hijeenu19-Jul-13 10:32
hijeenu19-Jul-13 10:32 
QuestionUpdate Shorthand? Pin
eddieangel19-Jul-13 8:37
eddieangel19-Jul-13 8:37 
AnswerRe: Update Shorthand? Pin
Dave Kreskowiak19-Jul-13 9:50
mveDave Kreskowiak19-Jul-13 9:50 
AnswerRe: Update Shorthand? Pin
Abhinav S19-Jul-13 18:48
Abhinav S19-Jul-13 18:48 
AnswerRe: Update Shorthand? Pin
Jean A Brandelero22-Jul-13 3:59
Jean A Brandelero22-Jul-13 3:59 
QuestionCalling VB 6 OCX from C# EXE Pin
matinon2219-Jul-13 2:18
matinon2219-Jul-13 2:18 
AnswerRe: Calling VB 6 OCX from C# EXE Pin
Dave Kreskowiak19-Jul-13 2:21
mveDave Kreskowiak19-Jul-13 2:21 
GeneralRe: Calling VB 6 OCX from C# EXE Pin
matinon2223-Jul-13 22:18
matinon2223-Jul-13 22:18 
GeneralRe: Calling VB 6 OCX from C# EXE Pin
Dave Kreskowiak24-Jul-13 3:52
mveDave Kreskowiak24-Jul-13 3:52 
QuestionGeneric collections Pin
PozzaVecia19-Jul-13 0:09
PozzaVecia19-Jul-13 0:09 
AnswerRe: Generic collections Pin
Nicholas Marty19-Jul-13 0:41
professionalNicholas Marty19-Jul-13 0:41 
GeneralRe: Generic collections Pin
PozzaVecia19-Jul-13 1:12
PozzaVecia19-Jul-13 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.