Thursday, November 19, 2009

Calling a service from a silverlight application

I was working on a Silverlight application that I intended to use on my GoDaddy hosted site and having trouble with calls to my WCF service (hosted on the same GoDaddy site).

Eventually, I found the following to work:

Uri GetServiceUri(String serviceName)
{
String fullPath = HtmlPage.Document.DocumentUri.ToString();
int index = fullPath.LastIndexOf('/');
Uri uri = new Uri(fullPath.Substring(0, index + 1) +
serviceName);
return uri;
}


Service2Client CreateService2Client()
{
return new Service2Client(new BasicHttpBinding(),
new EndpointAddress(GetServiceUri("Service2.svc")));
}



1 comment: