simendsjo
simendsjo

Reputation: 4749

Get Url for a WCF rest service

Is it possible to find the Url for a service and method?

An example:

class MainServiceModel {
   public string detailsUrl;
}

class MainService {
  MainServiceModel get() {
    return new MainServiceModel {
      detailsUrl = new Uri("how do I get DetailsService.ShowDetails url?");
    }
  }
}

class DetailService {
   string ShowDetails(string id);
}

Upvotes: 2

Views: 2508

Answers (2)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

My very high level idea is create custom ServicHost (and ServiceHostFactory if using IIS). When ServiceHost is instantiated you have access to service description and endpoints. You can grab information you need and store them somewhere for later reuse. You will have to use reflection on ServiceType to get operations relative URLs.

Btw. in WCF4 each service already shows this if you enable help page.

Upvotes: 0

marc_s
marc_s

Reputation: 754220

Try checking out the OperationContext:

OperationContext oc = OperationContext.Current;
string wasCalledOn = oc.EndpointDispatcher.EndpointAddress.Uri.ToString();

The operation context also contains a wealth of other information about the current operation and parameters for it.

Update: if you want to call Service B from your method in Service A, you should create a client-side proxy in Service A. By doing so, you will get some configuration entries, and then you should be able to easily call a method on Service B from your Service A method.

ok, so that's not it....

Upvotes: 3

Related Questions