Deka
Deka

Reputation: 131

WebRequest results with "URI prefix is not recognized."

I am trying to get WebReguest for the "mms://wms.iskon.hr/Novi20%25radio20%25Djakovo", but instead I get NotSupportedException saying:The "URI prefix is not recognized." Code I use is pretty simple:

Uri uri = new Uri(watchedStream.URL.Trim());
WebRequest wr = WebRequest.Create(uri);

Mms scheme is the source of this problem, but I just can't figure out working solution.

Update: After some brewing I finally got the response, but I can't get WebResponse(). Now my code generates "502 Bad gateway exception". This new code:

 Uri uri = new Uri(watchedStream.URL.Trim());
 WebRequest wr = WebRequest.Create("http://" + Dns.GetHostAddresses(uri.DnsSafeHost)[0].ToString() + ":1755");
 WebResponse = wr.GetResponse();

Upvotes: 2

Views: 9325

Answers (3)

NoWar
NoWar

Reputation: 37662

You can use WPF MediaElement in order to check it.

Try this code.

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += MainWindow_Loaded;
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                MediaElement me = new MediaElement();
                me.MediaEnded += me_MediaEnded;
                me.MediaFailed += me_MediaFailed;
                me.MediaOpened += me_MediaOpened;

                me.Source = new Uri("mms://95.0.159.131/TRTBELGESEL");

                mainGrid.Children.Add(me);
            }
            catch (Exception ex)
            {   
            }
        }

        void me_MediaOpened(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("OPENED"); //  It means OK!
        }

        void me_MediaFailed(object sender, ExceptionRoutedEventArgs e)
        {
            Debug.WriteLine("FAILED"); // It means that URL is not working
        }

        void me_MediaEnded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("ENDED");
   }
    }

Upvotes: 0

PhilPursglove
PhilPursglove

Reputation: 12589

From looking at the MSDN page on WebRequest and specifically at its' inheritance it looks like this is because WebRequest only supports the file, http and ftp schemes.

Edit: I just did some playing with WebClient to see if it could be coaxed into downloading some data, but it uses WebRequest under the covers so you get the same exception :-( However, there's a comment on the WebClient MSDN page that states that

By default, the .NET Framework supports URIs that begin with http:, https:, ftp:, and file: scheme identifiers

which we kind of already knew. However there's a comment right above there that states

WebClient instances can access data with any WebRequest descendant registered with the WebRequest.RegisterPrefix method.

This suggests that you should be able to create a class that implements IWebRequestCreate, which you can then register to support the mms scheme, then you may be able to get to your data. WebRequest.RegisterPrefix

Upvotes: 2

Tony Abrams
Tony Abrams

Reputation: 4673

The problem is that the MMS protocol is not meant (or supported) to be be used as a URI. It seems that you are supposed to use it as a 'rollover URL'.

See following:

MMS Wikipedia

Eggheadcafe posting

Upvotes: 0

Related Questions