Social Icons

twitter google plus linkedin rss feed

Pages

25.2.12

CrossDomain SecurityException accessing my Azure WCF Service from Silverlight

Just uploaded a WCF Service Web Role to Azure with the intention of accessing it from a Silverlight web part, but I got the dreaded and almost expected:
System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://localhost:81/MyService.svc'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
Yes, cool, but how do I add my crossdomain.xml or my clientaccesspolicy.xml files to an “Azure Web Role” which I just heard exists?

To my surprise it’s very easy you just have to add the XMLs to the project:

adding crossdomain.xml and clientaccesspolicy.xml to azure web role

Then you’ll be able to debug and, after you “Upgrade” the package in Azure Hosted service, you’ll be able to access it from Silverlight.

By the way, I don’t like "Upgrade" here, I find it misleading. I would have used Update.

No comments:

Post a Comment

20.2.12

MessageBox, DialogBox and Popup windows in Silverlight with the ChildWindow control

I know this has been around since Silverlight 3, but I didn’t know about it! Really? I can't believe it!

So for me is new and it looks great. In the past I have created user controls for this, but this ChildWindow has even animations…

To create it is as simple as adding a new item of this class to the project:

Create a new Silverlight Child Window
And then, tweak a bit the XAML to make it look the way you need and that’s all.

To use it you just have to create it and show it like this:
MessageWindow window = new MessageWindow("Info!", string.Format("This is a ChildWindow example."), true);
window.Show();

As always, there’s a catch. Unlike the MessageBox it won’t stop the thread waiting for your reply (this is also good in some cases, I have found lately that the MessageBox dialogs are quite resource cosuming) so if you want to use the response the user has selected in your ChildWindow you should subscribe to the Close event, something like this:
MessageWindow window = new MessageWindow("Info!", string.Format("This is a ChildWindow example."), true);
window.Show();

window.Closed += (sndr, args) =>
{
    if (window.DialogResult == true)
    {
        StratexWS.GetFBAUsersAsync();
        LoadingWindow.Show();
    }
};

I have tweaked a bit the OOTB code. Mine looks like this:

ChildWindow example
By the way, there’s at least another catch, it won’t work in the constructor… it only works after the control has been loaded (http://vanderbiest.org/blog/2010/08/03/silverlight-4-childwindow-is-not-visible/)

No comments:

Post a Comment