Click here to Skip to main content
15,891,253 members
Home / Discussions / C#
   

C#

 
AnswerRe: Finding Classes that implement a certain Class Pin
Skippums12-Oct-07 7:10
Skippums12-Oct-07 7:10 
GeneralRe: Finding Classes that implement a certain Class Pin
Fayu12-Oct-07 7:40
Fayu12-Oct-07 7:40 
AnswerRe: Finding Classes that implement a certain Class Pin
led mike12-Oct-07 7:17
led mike12-Oct-07 7:17 
GeneralRe: Finding Classes that implement a certain Class Pin
Fayu12-Oct-07 7:42
Fayu12-Oct-07 7:42 
GeneralRe: Finding Classes that implement a certain Class Pin
Skippums12-Oct-07 8:02
Skippums12-Oct-07 8:02 
GeneralRe: Finding Classes that implement a certain Class Pin
Fayu12-Oct-07 8:42
Fayu12-Oct-07 8:42 
QuestionUDPClient Recieve port [modified] Pin
Riot_starter12-Oct-07 6:26
Riot_starter12-Oct-07 6:26 
QuestionCasting a WebService instance to a custom interface Pin
MrEyes12-Oct-07 5:47
MrEyes12-Oct-07 5:47 
Heres an interesing (I hope) question

The short version of the question:

Is it possible to cast an instance of a WebService reference to an custom interface (the webservice contains the methods as defined in the interface)

The long version:

I have an application framework that consists of the following key components:

(A) Client API
(B) Server WebService
(C) Server Remoting Listener / Application

In runtime, the Client API pushes requests onto the Server WebService, which inturn pushes them onto the Server Remoting Listener / Application.

So as an example the Client API exposes a DoSomething method which calls the DoSomething web service method, which calls the DoSomething Server Remoting Listener / Application method, the return value of which is returned back up the tree.

In order to maintain a degree of control (and for remoting) all of these components use a common interface, i.e.

public interface IFrameworkMethods
{
  int DoSomething();
}


The reason for all these degrees of seperation is that typically all three components are on different devices to split the load across the enterprise. For reasons of policy connectivity from client to server farm must be across HTTP however within the farm I can use remoting. All decisions that cannot be changed.

Now heres the question:

Under some configurations the Client API and Server Remoting Listener / Application are on the same device. As such it seems sensible to not take the performance hit of performing a HTTP post to localhost, and to push the requests directly onto the local listener.

In the first run of the code, I simply did something like this:

public int DoSomething()
{
  int resultCode = 0;

  if (directRemotingAvailable)
  {
    //create necessary remoting objects
    resultCode = remotingObject.DoSomething();
  }
  else
  {
    //create necessary web service access objects
    resultCode = webServiceObject.DoSomething();
  }

  return resultCode;
}


This obviously works, but this API exposes alot of methods so it is alot of if/else and bloat. Which got me thinking, I am using the interface for remoting, so why not use the interface defintion for the webservice as well.

So my Client API method now looks something like this:

public int DoSomething()
{
  IFrameworkMethods obj = GetInterface();
  int resultCode = obj.DoSomething();
}

private IFrameworkMethods GetInterface()
{
  IFrameworkMethods obj = null;

  if (configIsRemoting)
  {
    //set obj to remoting interface here
  }
  else
  {
    FrameworkMethodsWebService ws = new FrameworkMethodsWebService()
    //set ws properties (i.e. proxy settings etc etc etc)

    //hmmm, there seems to be a problem casting the
    //web references to the IFrameworkMethods interface
  }
}


As you may have seen the problem I have surrounds the fact that I cannot cast/convert an instance of the FrameworkMethodsWebService to an interface of IFrameworkMethods. Which is fair enough, at the end of the day, they are entirely different objects.

So the question is based on this architecture can this be done somehow? and if so please prod me in the right direction.







-- modified at 11:54 Friday 12th October, 2007
AnswerRe: Casting a WebService instance to a custom interface Pin
led mike12-Oct-07 6:59
led mike12-Oct-07 6:59 
GeneralRe: Casting a WebService instance to a custom interface Pin
MrEyes12-Oct-07 8:23
MrEyes12-Oct-07 8:23 
GeneralRe: Casting a WebService instance to a custom interface Pin
led mike12-Oct-07 9:54
led mike12-Oct-07 9:54 
QuestionCan't Break point ASP Project Pin
smarttom9912-Oct-07 5:09
smarttom9912-Oct-07 5:09 
AnswerRe: Can't Break point ASP Project Pin
martin_hughes12-Oct-07 5:21
martin_hughes12-Oct-07 5:21 
GeneralRe: Can't Break point ASP Project Pin
smarttom9913-Oct-07 4:29
smarttom9913-Oct-07 4:29 
GeneralRe: Can't Break point ASP Project Pin
martin_hughes13-Oct-07 6:03
martin_hughes13-Oct-07 6:03 
QuestionModal Dialogs Pin
Skippums12-Oct-07 5:05
Skippums12-Oct-07 5:05 
AnswerRe: Modal Dialogs Pin
TJoe12-Oct-07 6:13
TJoe12-Oct-07 6:13 
GeneralRe: Modal Dialogs Pin
Skippums12-Oct-07 6:27
Skippums12-Oct-07 6:27 
GeneralRe: Modal Dialogs [modified] Pin
Fayu12-Oct-07 7:22
Fayu12-Oct-07 7:22 
QuestionRe: Modal Dialogs Pin
Skippums12-Oct-07 7:02
Skippums12-Oct-07 7:02 
AnswerRe: Modal Dialogs Pin
Luc Pattyn12-Oct-07 7:20
sitebuilderLuc Pattyn12-Oct-07 7:20 
GeneralRe: Modal Dialogs Pin
Skippums12-Oct-07 7:59
Skippums12-Oct-07 7:59 
AnswerRe: Modal Dialogs Pin
Luc Pattyn12-Oct-07 7:53
sitebuilderLuc Pattyn12-Oct-07 7:53 
QuestionBase data Pin
RussBus12-Oct-07 4:51
RussBus12-Oct-07 4:51 
AnswerRe: Base data Pin
led mike12-Oct-07 4:57
led mike12-Oct-07 4:57 

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.