I am trying to use the Azure MediaService API
along with the Azure Storage API
in an API Service
hosted in Azure
.
The user sends the video stream to the service as an HttpPost
, the service saves the video as a blob in my Storage account, the media service encodes the video and when the link to the video is ready it is returned to the user.
But when I am trying to create an Asset
a System.NotSupportedException
is thrown with the message:
Exception thrown: 'System.NotSupportedException' in Microsoft.Data.Services.Client.dll Exception thrown: 'System.NotSupportedException' in mscorlib.dll iisexpress.exe Error: 0 : Exception=System.NotSupportedException: This target framework does not enable you to directly enumerate over a data service query. This is because enumeration automatically sends a synchronous request to the data service. Because this framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to obtain a query result that supports enumeration.
I am using the following versions of the required dependencies:
Microsoft.Data.Services.Client - 5.6.2.0 Microsoft.WindowsAzure.MediaServices.Client - 3.0.0.8 Microsoft.WindowsAzure.Storage - 3.1.0.1
Here is my code:
CloudMediaContext _context; IAsset asset; using (MemoryStream Ms = new MemoryStream(data.Data)) { _context = new CloudMediaContext("accountName", "accountKey"); asset = await _context.Assets.CreateAsync("blobContainerName", AssetCreationOptions.None,CancellationToken.None); ... ... }
The data.Data
contains the byte[]
of the video. The exception is thrown when CreateAsync
is called. I tried _context.Assets.Create
with no luck.
IMPORTANT EDIT
I created a new console application, used the code I am using in the API Service and it was executed successfully. So the problem is in the API Service.
Here is my class and method definitions
public class UploadController : ApiController { [HttpPost] public async Task<string> PostUpload(VideoData data) { ... ... }
Any alternative to that maybe?
I was able to create a working demo using a .NET 4.6.1 and following nuget package:
windowsazure.mediaservices v3.6.0.0
web.config
(if doesn't exists) https://social.msdn.microsoft.com/Forums/azure/en-US/eb05a115-36b2-47a5-b464-3220548a5de9/upgrade-to-media-services-sdk-20-error-with-microsoftpracticestransientfaulthandlingcore?forum=MediaServices [HttpPost] public async Task<string> PostUpload() { var bytes = System.Text.Encoding.UTF8.GetBytes("Test"); var data = new VideoData { Data = bytes }; CloudMediaContext _context; using (MemoryStream ms = new MemoryStream(data.Data)) { var accountName = "accountName"; var accountKey = @"primaryaccessKey"; _context = new CloudMediaContext(accountName, accountKey); var asset = await _context.Assets.CreateAsync("myjblobassets", AssetCreationOptions.None, CancellationToken.None); //... do something with asset and ms ... } return "http://my-link"; }
* Note: any bytes is fine here since we are not demonstrating the upload part, we are making sure creating a Media Service Asset works.
form
and submit button
in the index view pointing to this post action, run it and works!!!Note: In NAME, enter the name of the new account. A Media Services account name is all lower-case numbers or letters with no spaces, and is 3 - 24 characters in length. https://azure.microsoft.com/en-us/documentation/articles/media-services-dotnet-get-started/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With