Saturday, September 01, 2007

WCF Addressing

You can specify an absolute address for each endpoint or you can supply the ServiceHost with a base address and then specify relative paths for each endpoint. Specifying absolute addresses is a little easier to understand, but the base address technique typically makes things easier to manage.

The base address technique is mostly a convenience to reduce the number of places you’ll have to make changes when modifying the locations of your endpoints. Windows Communication Foundation also uses the base HTTP address by default to expose metadata when GET retrieval has been enabled (via the serviceMetadata behavior). You can, however, change the retrieval location using the behavior’s httpGetUrl property.

It’s also possible to specify the base addresses in the configuration file along with the endpoints themselves by listing the base addresses within the host element for each service.

IIS Addressing Considerations

When hosting in IIS, you simply map a .svc endpoint to your service class, configure the service endpoints and behaviors in web.config, and let WCF manage the process of creating and configuring the ServiceHost instance at runtime.

In this hosting scenario, the base HTTP address is determined by the IIS virtual directory housing the service along with the name of the .svc file. If you want to change the base address for your endpoints, you’ll need to move the service to a different IIS virtual directory.

Not only does IIS control the base address, it forces all of your endpoints to actually use the same base address (unlike self-hosting). As a result, it really only makes sense to use relative addresses when hosting in IIS.

Suppose you have a file named calc.svc and you place it in a virtual directory that corresponds to http://localhost:8080/calcservice. The base address for this service will be http://localhost:8080/calcservice/calc.svc. If a relative addresss "secure" is provided, then its address is http://localhost:8080/calcservice/calc.svc/secure. You have to remember that calc.svc is part of the base address so it has to work this way.

Logical vs. Physical Addresses

WCF refers to the logical address as "Address" or "Endpoint Address" and the physical address as "ListenUri".

From Service Station: WCF Addressing In Depth by Aaron Skonnard.


Post a Comment

<< Home