Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Tuesday, August 10, 2010

Dynamically Computing Web Service Addresses for Azure-Silverlight Applications

If you work with Silverlight or with Windows Azure you can experience some pain when it comes to getting your WCF web services to work at first. If you happen to be using both Silverlight and Azure together you might feel this even more.

One troublesome area is the Silverlight client knowing the address of its Azure web service. Let’s assume for this discussion that your web service is a WCF service that you’ve defined in a .svc file (“MyService.svc”) that resides in the same web role that hosts your Silverlight application. What’s the address of this service? There are multiple answers depending on the context you’re running from:
  1. If you’re running locally, your application is running under the Dev Fabric (local cloud simulator), and likely has an address similar to http://127.0.0.1:81/MyService.svc.
  2. If you run the web project outside of Windows Azure, it will run under the Visual Studio web server and have a different address of the form http://localhost:<port>/MyService.svc.
  3. If you deploy your application to a Windows Azure project’s Staging slot, it will have an address of the form http://<guid>.cloudapp.net/MyService.svc. Moreover, the generated GUID part of the address changes each time you re-deploy.
  4. If you deploy your application to a Windows Azure project’s Production slot, it will have the chosen production address for your cloud service of the form http://<project>.cloudapp.net/MyService.svc.
One additional consideration is that when you perform an Add Service Reference to your Silverlight project the generated client configuration will have a specific address. All of this adds up to a lot of trouble each time you deploy to a different environment. Fun this is not.

Is there anything you can do to make life easier? There is. With a small amount of code you can dynamically determine the address your Silverlight client was invoked at, and from there you can derive the address your service lives at.

You can use code similar to what’s shown below to dynamically compute the address of your service. To do so, you’ll need to make some replacements to the MyService = … statement:
1. Replace “MyService.MyServiceClient” with the namespace and class name of your generated service proxy client class.
2. Replace “CustomBinding_MyService” with the binding name used in the generated client configuration file for your service endpoint (ServiceReferences.ClientConfig).
3. Replace “MyService.svc” with the name of your service .svc file.

string hostUri = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUri;
int pos = hostUri.LastIndexOf('/');
if (pos != -1)
{
    hostUri = hostUri.Substring(0, pos);
}
MyService.MyServiceClient MyService = new MyService.MyServiceClient("CustomBinding_MyService", hostUri + "/MyService.svc");

With this in place you can effortlessly move your application between environments without having to change addresses in configuration files. Note this is specific to “traditional” WCF-based web services only. If you’re working with RIA Services, the client seems to know its service address innately and you should not need to worry about computing web service addresses.

Monday, October 26, 2009

Voice 2.0 for Silverlight/Azure is Coming November 5, 2009


Would you like to add voice and telephony capabilities to your Silverlight and Azure applications? Think of the extra dimension of user experience that could add to your Rich Internet Applications. Now you can, and the premier event to learn all about it (in person if you’re in the San Francisco area, else via webcast) is coming up on November 5, 2009.

For several months now I’ve been part of a Microsoft-Ribbit-Neudesic collaboration working to make Ribbit’s Voice 2.0 technology available to Silverlight developers in the form of customizable Silverlight controls integrated with Visual Studio and Expression Blend. Now that I’m allowed to start talking about it, I want to encourage Silverlight and Azure developers to attend the debut announcement and demo of Ribbit for Silverlight at Ribbit’s upcoming developer event, Spawn. After the event, I’ll be posting more about developing Voice 2.0 applications using Ribbit for Silverlight.

Here’s the official announcement from Ribbit:

Please join Ribbit in San Francisco November 5, 2009 for a deep dive into our open telephony APIs.

We’re excited to formally launch our RESTful API, and we’re looking for early adopters like you!

In the network of the future:
• Voice will simply be another data object – and will be carrier, network, device and protocol agnostic
• Legacy carrier networks will be merged with open networks / the internet
• Innovation will be developer driven, not constrained by existing carrier / telco business models

Ribbit is revolutionizing the communications paradigm by providing an open and fully programmable global communications platform. This platform allows any developer to integrate voice, messaging, and rich communications into any application, on Web experience.

Join us for a day of innovation and learning and an evening of coding and cocktails.

Ribbit + REST = Open Programmable Communications

Rebuilding the Ribbit Platform on top of a RESTful framework allows developers to interact with Ribbit at the server level, enabling new forms of application-to-person and application-to-application services. REST treats users, devices, calls, messages, and other elements as resources with which developers can easily interact — and exposes Ribbit’s core communications services in a platform-agnostic format using simple and secure HTTP calls.

Space is limited, Register ASAP! http://developer.ribbit.com/blog/spawn/

If you cannot attend in person, please join us via webcast. Register by 11/3 at: http://developer.ribbit.com/blog/spawn-webcast/

Agenda

8:00 – 9:00 Registration and continental breakfast
9:00 – 10:00 Ribbit Platform Overview — New Features, Platform Roadmap & Pricing
10:00 – 11:00 Integrating Ribbit into Any Application, Workflow, Site or Online Campaign
11:00 – 11:30 New APIs and application showcase
11:30 – 12:00 Platform opportunities
12:00 - 1:00 Lunch

1:00 - 2:45 Afternoon Breakout Sessions
• Flash
• Java
• .NET
• PHP

3:00 – 4:45 Afternoon Breakout Sessions
• Building Client-and Server-Side Apps
• JavaScript
Silverlight
• REST

5:00 - 9:00 Hands-On Coding with Ribbit’s API/Programming Language Experts
Coding for Flash, Silverlight
• Coding for Java, JS, PHP, REST, .NET

We look forward to seeing you there!

Team Ribbit

Ribbit is an open, cloud-based platform for communications innovation. By exposing our carrier-grade SmartSwitch™ though popular programming APIs, Ribbit enables the development of next generation “voiceware” applications, such as our white-labeled Ribbit for Salesforce® and Ribbit Mobile™ applications.