views:

169

answers:

2

Ive just started using WCF with silverlight and its working fine. But one thing that is bugging me is the address of the .svc. Why is it statically set in the .config? Would it be possible to set it when creating an instance of the proxy class? And if so, is there a way to set it to the current address? Our software will be deployed on many different domain and we cant change the config every time. The svc will always be in the same domain as the silverlight page. Thanks.

+1  A: 

You can specify a custom ServiceHost with the factory parameter in your .svc file then you can configure the endpoint however you need from there in code, including a relative address.

see: http://msdn.microsoft.com/en-us/library/aa395224.aspx http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx

Also see this answer

Dog Ears
Thanks Dog Ears!
Matt
+1  A: 

"Would it be possible to set it when creating an instance of the proxy class?"

Yes you can. Just pass the address as a parameter of the client's constructor. You don't need a custom ServiceHostFactory for that.

"Our software will be deployed on many different domain and we cant change the config every time."

Also for this requirement, you shouldn't be required to do any extra work on the server side. Only the client obviously needs to know the address to connect to.

Alex