Stream video from secure azure blob to WPF - wpf

Does anyone know a way to stream .mp4 video from a secure azure blob (via https) into a WPF application.
I'm generating the uri as follows ...
public Uri GetSecureUriForBlob(CloudBlobContainer container, string blobName)
{
var blockBlob = container.GetBlockBlobReference(blobName);
var beforeOffset = new DateTimeOffset(DateTime.UtcNow.AddMinutes(-5));
var afterOffset = new DateTimeOffset(DateTime.UtcNow.AddHours(1));
var builder = new UriBuilder(blockBlob.Uri)
{
Query = blockBlob.GetSharedAccessSignature(
new SharedAccessBlobPolicy
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = beforeOffset,
SharedAccessExpiryTime = afterOffset
}).TrimStart('?')
};
return builder.Uri;
}
I've checked that the service version is set to at least "2013-08-15" and that the blob item has the correct content type set.
I know the format of the uri is correct, because I can paste it in a browser, and also use it in a Windows 8 store application, and the video streams correctly.
However, when I assign the same uri as the source for a WPF MediaElement, I get a NullReferenceException deep in the inner workings of MediaPlayer.Open().

There seems to be a known issue with WPF MediaElement when playing from HTTPS endpoints. There are no issues when playing over plain HTTP (without "S").
This is not Microsoft Azure related, or Blob Related. This is pure WPF issue, that however seems that will not be fixed soon, if fixed at all.
For HTTPS Streams you can use either Silverlight or Windows 8 Modern applications - both support HTTPS streams without any issues.
You could probably find a 3rd party control for WPF that supports playing media over HTTPS.
UPDATE
Using the VideoLan.NET WPF Controls I was able to make HTTPS media playing. So far the only controls for WPF that successfully play HTTPS media. This requires a valid installation of VideoLAN VLC player for Windows. I used the portable one (ZIP package) and it works perfectly. Documentation for the VideoLan.NET is a bit messy, but the result is that you can safely play HTTPS streams/progressive downloads in WPF.

Related

Upload local database to SkyDrive as a textfile

I havent looked at the samples yet for the SkyDrive.
I have done a application that saves some data in a local database on the phone.
What i want to do is to upload all these to a SkyDrive account as a textfile.
Is this possible?
Might want to start with a blog post I wrote - Adding SkyDrive support to your Windows Phone application. You will need to download the Live SDK (unless you want to use the REST API manually, which I can see no reason for at this point).
Uploading is fairly simple after that, given that you obtained the proper session init:
client = new LiveConnectClient(App.MicrosoftAccountSession);
client.UploadCompleted += MicrosoftAccountClient_UploadCompleted;
client.UploadProgressChanged += MicrosoftAccountClient_UploadProgressChanged;
client.UploadAsync("me/skydrive", Binder.Instance.CurrentlyUploading,
stream, OverwriteOption.Overwrite);
Where stream is a MemoryStream instance.

Consume SOAP Web Service in Silverlight

I'm attempting to consume a SOAP service in a Silverlight 5 application and I'm completely lost. This is my first Silverlight app and only my second time using web services in a .NET application.
In a separate .NET application, the only way I was able to get it to work was by adding the WSDL as a Web Reference; the application would not build when I added it as a Service Reference. In talking to the WSDL provider, I discovered that the WSDL was compiled using the .NET 2.0 framework...hence the need to add it as a Web Reference.
From the research I've done thus far, I see that Silverlight doesn't support adding a Web Reference. So I tried adding it to the hosting ASP.NET application as a Web Reference then started the server.
Back in my Silverlight app, I selected the option to add a Service Reference and pointed to the WSDL file now at http://localhost:55265/Web%20References/THINKWebService/SLWebSvc_734_Upgrade.wsdl. Visual Studio seemed to pick it up just fine and generate the proxies.
Here's where I start to get stuck. If my research is correct, a WCF reference was created and should be used in that manner. I've never used WCF so I did some reading on how to send/receive requests and this is the best code I've come up with, based on examples in the MSDN library (I inserted it into a button click event so I would know exactly when the code was executing):
private void Button1Click(object sender, RoutedEventArgs e)
{
var client = new ThinkSoapClient();
var userLoginData = new user_login_data {login = "foo", password = "bar"};
var customerIdentifier = new customer_identifier {customer_id = 6677070};
// the debugger halts on this next line and
// references the "dsn"...it's the 4th argument
client.CustomerLoginInfoSelectAsync(userLoginData, customerIdentifier, "", "myDSN");
// I'm not sure if this next line is even needed
client.CustomerLoginInfoSelectCompleted += CustomerLoginInfoSelectCallback;
MessageBox.Show(string.Format("CustomerLoginInfoSelectAsync({0},{1})", userLoginData, customerIdentifier));
}
// here's the callback method
static void CustomerLoginInfoSelectCallback(object sender, CustomerLoginInfoSelectCompletedEventArgs e)
{
MessageBox.Show(string.Format("CustomerLoginInfoSelect Result: {0}", e.Result));
}
As I mentioned in the code above, the debugger halts when executing the client.CustomerLoginInfoSelectAsync method. Here's the error message: XmlSerializer attribute System.Xml.Serialization.XmlAttributeAttribute is not valid in dsn. Only XmlElement, XmlArray, XmlArrayItem and XmlAnyElement attributes are supported when IsWrapped is true.
From the research I've done, I think this error is being caused because the the SOAP action element contains an attribute dsn (not sure, though, if I would be getting this error if the sub-elements also had attributes).
I did a find/replace for IsWrapped=true to IsWrapped=false in Reference.cs but I got the same error but the last word was false instead of true.
I'm not sure if I'm making any sense as to what I'm after, so here's what the generated XML should look like in case it helps:
...
<customer_login_info_select_request dsn="myDSN">
<user_login_data>
<login>foo</login>
<password>bar</password>
</user_login_data>
<customer_identifier>
<customer_id>6677070</customer_id>
</customer_identifier>
<login/> <!--corresponds to the empty string in the call to CustomerLoginInfoSelectAsync-->
</customer_login_info_select_request>
...
So at this point, I'm completely lost. Any insights would be greatly appreciated. If there's any other info I can provide, please let me know.
While possible the normal solution would be to assume it is "just another data source" and use the Web reference on your Server side instead to provide data (and to provide insulation against future changes).
Silverlight App <=> Silverlight Web Services <= External/Legacy Web Service
Keep your Silverlight app slim and let the server do any heavy lifting for you.

Text To Speech in Silverlight 4

I am creating an application which converts text to speech using silverlight 4.0. Two options which I found can be used are:
Use TTS at client side, which requires the application to be run OOB. Also since it uses native windows components, can't be used in any other platforms (MAC).
Use TTS conversion at WCF end. This again requires the WCF service to be hosted on IIS with Local System account for application pool.
Are there any other options in which we dont have to provide the elevated permissions?
The Bing translator service has TTS for several languages. Maybe it is possible to just use the TTS part without the translation. This blog post explains how to call the service and perform TTS from Silverlight:
http://timheuer.com/blog/archive/2010/03/22/silverlight-translator-text-to-speech-api.aspx
Another good solution is using google TTS - http://translate.google.com/translate_tts
The code would be like this:
string url = string.Format("http://translate.google.com/translate_tts?tl=en&q={0}", textToSay);
WebClient client = new WebClient();
return client.DownloadData(url);
If using silverlight, the data which is fetched from the above code(in byte array), can be set as the source of media element with converting to memore stream as below:
_audioPlayer.SetSource(new MemoryStream(textToSpeech));
Where textToSpeech is the byte array as returned from google tts.

Config/Settings for a Microsoft CRM 2011 Form Silverlight Control

Need an idea on best practise in finding a solution.
We are looking at developing Silverlight controls for CRM forms that will need to reference a common configuration file for data. It is a file that will need to be maintained periodically every once in a while. We don't want to be hardcoding values into the Silverlight control.
My question is... Where/What/How do we provide a config file for a Silverlight control?
I tried uploading a JS web resource that simply was a JSON array full of settings that I tried to access from the Silverlight control. All I got were permission errors when I used both the admin account and my domain account to do a Http get of the file and parse it. Can someone confirm that this could work if I manage to work through these annoying permission errors?
My next thought was having a CRM entity full of settings that the Silverlight control could make ODATA calls to in order to get its config data. I'm not 100% sold on the idea though.
Perhaps there is another way people have been using - if so - I'd love to see what you are doing. This could really prevent us from coming to a Silverlight enriched solution that we are after.
Thanks in advance
We go about this in two ways.
We have a configuration entity for settings that might be changed on a customer site by their administrator.
For other configuration data that is unlikely to be changed, we install an XML web resource. This method means we can store a lot of data without having to create and manage complex entities (or relationships if required). If set as an unmanaged/customizable web resource, then the text editor can be used to make changes, although remember that these changes must not break the XML schema/syntax.
This xml web resource can be retrieved in Silverlight using WebClient.DownloadStringAsync() as shown below.
private void GetXmlConfiguration(string resourceName)
{
var webClient = new WebClient();
webClient.DownloadStringCompleted += OnGetConfigurationXmlCompleted;
webClient.DownloadStringAsync(new Uri("../Data/" + resourceName, UriKind.Relative));
}
private void OnGetConfigurationXmlCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null && !string.IsNullOrEmpty(e.Result))
{
//use xml string here
}
}
We use the configuration entity method quite often and I think it works well.
You should be able to use your initial method as well... I know in a few places we've done some XML configuration in a web resource that we've retrieved in Silverlight, parsed, and done something with.

Silverlight 4 webclient authentication - anyone have this working yet?

So one of the best parts about the new Silverlight 4 beta is that they finally implemented the big missing feature of the networking stack - Network Credentials!
In the below I have a working request setup, but for some reason I get a "security error" when the request comes back - is this because twitter.com rejected my api call or something that I'm missing in code?
It might be good to point out that when I watch this code execute via fiddler it shows that the xml file for cross domain is pulled down successfully, but that is the last request shown by fiddler ...
public void RequestTimelineFromTwitterAPI()
{
WebRequest.RegisterPrefix("https://", System.Net.Browser.WebRequestCreator.ClientHttp);
WebClient myService = new WebClient();
myService.AllowReadStreamBuffering = true;
myService.UseDefaultCredentials = false;
myService.Credentials = new NetworkCredential("username", "password");
myService.UseDefaultCredentials = false;
myService.OpenReadCompleted += new OpenReadCompletedEventHandler(TimelineRequestCompleted);
myService.OpenReadAsync(new Uri("https://twitter.com/statuses/friends_timeline.xml"));
}
public void TimelineRequestCompleted(object sender, System.Net.OpenReadCompletedEventArgs e)
{
//anytime I query for e.Result I get a security error
}
I found 2 issues that caused this request to throw the security exception
1) - In this video by Tim Heuer it turns out my VS2010 w/ Silverlight 4 toolkit installation didn't match the final build so I'm missing the option that shows up in the "out of browser settings" dialog that provides the checkbox for "Require elevated trust when running outside the browser".
In the video listed above Tim checks this so the Silverlight app can talk to the twitter API
But because my application didn't have this option I had to manually edit the xml file so it looked like the below. You can find this xml under properties in the project folder or inside visual studio directly.
<OutOfBrowserSettings ShortName="TrustedNetworkApp Application" EnableGPUAcceleration="False" ShowInstallMenuItem="True">
<OutOfBrowserSettings.Blurb>TrustedNetworkApp Application on your desktop; at home, at work or on the go.</OutOfBrowserSettings.Blurb>
<OutOfBrowserSettings.WindowSettings>
<WindowSettings Title="TrustedNetworkApp Application" Height="480" Width="640" />
</OutOfBrowserSettings.WindowSettings>
<OutOfBrowserSettings.SecuritySettings>
<SecuritySettings ElevatedPermissions="Required" />
</OutOfBrowserSettings.SecuritySettings>
<OutOfBrowserSettings.Icons />
</OutOfBrowserSettings>
Notice the **security settings ElevatedPermissions="Required"
After you save this it's equivalent to checking this as Tim did in the video.
2) - as I was watching that video by Tim I noticed that you have to debug this outside of the browser to get it working. So install the app and run it outside the browser. This app now works.
I'll write a short blog post to summarize my experience with the networking stack under the beta and link to it for anyone interested.
Update
I finally wrote a blog post about my experience building an out of browser twitter client using Silverlight 4 if anyone is interested.

Resources