Calling one WCF service from another... or am I?
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
RemoteSer开发者_如何转开发vice.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?
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.
精彩评论