Problem with localhost in WCF service

21 May

In any cases you will use a WCF service to communicate with a server from your Silverlight client (in more and more cases you will probably use WCF RIA Services but that is an entirely different story).

The problem

To communicate between your client and server you need to generate a proxy. The proxy will contain the endpoint address specified as part of the service reference. In most cases the endpoint address will be localhost and it can be configured in ServiceReferences.ClientConfig.

image

At compile time the ServiceReferences.ClientConfig will be put into your XAP file. If you need to change the endpoint address in an other environment you need to change it inside the XAP file in the corresponding environment.

This is not a very flexible solution.

A more flexible solution

A more flexible solution would be to specify the endpoint address as part of the server configuration. And that is possible!

Instead of getting the endpoint address from ServiceReferences.ClientConfig you can sent it to the client as init parameter (initParams). When initializing the servicereference you will need to specify the binding you wish to use and the new endpoint.

image

In most cases you will refactor this out to some more generic methods but the point is simple and it will allow you to specify your endpoint address in a more flexible way.

Source code

Get the source code and a demo here: http://bit.ly/cPqoa6

Read more

http://bit.ly/9y7mtv
http://bit.ly/cU166b

by xamlgeek
twitter.com/thomasmartinsen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: