views:

110

answers:

1

I'm trying to make a call to a remote WCF service from within an existing service.

I've added a Service Reference to the method I need to consume in the remote service, and use it as follows in this WebMethod of my own service:

  [WebMethod(Description = "My local service."]
  public RemoteService.ServiceResponse ServiceRequest(RemoteService.SendRequest myObject)
  {
       // Instance of remote service's method I'm 
       RemoteService.ServiceResponse SendResponse;

       SendResponse = ServiceRequest(RemoteService.SendRequest)    

       return SendResponse;
  }

My question, with the call to the ServiceRequest web method of the remote service, am I actually calling the remote service?! Or, am I just calling my own local instance of the remote service's ServiceRequest method?

If I'm right about my being wrong, what would be the proper way to do what I need to do, to kind of act I guess as a passthrough or proxy to pass requests and responses to and from my service and the remote service?

+2  A: 

First of all, the [WebMethod] attribute would point to ASMX webservice - not WCF. Is it really WCF??

Second, if it IS WCF: in order to call a method on a service, you need to instantiate a proxy client for that service. When you generated your service reference, you should have gotten a ServiceNamespace.ServiceReferenceClient class of sorts - it's been autogenerated for you. You need to instantiate this and call the method on that proxy:

[WebMethod(Description = "My local service."]
public RemoteService.ServiceResponse ServiceRequest(RemoteService.SendRequest myObject)
{
       // Instance of remote service's method I'm 
       RemoteService.ServiceResponse SendResponse;

       ServiceProxyClient client = new ServiceProxyClient();    

       SendResponse = client.ServiceRequest(RemoteService.SendRequest)    

       return SendResponse;
  }

That way, you are indeed calling the service you just added as a Service Reference.

marc_s
Great answer! The only thing I would add is that if both services are on the same machine, and it sounds like they are, you should consider using the netNamedPipes binding. It's designed for situations where the client and service are on the same box and is VERY fast.
James Bender
Marc, I'm still new to web services in general and I'm still digesting the terminology; thanks much, this really clears the murk I was seeing earlier this morning. :) James, yes ultimately both services will run off the same server, so I'll do as you suggest and enable the netNamedPipes binding.
Darth Continent