• Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media Services 3.0

    Published by Ezequiel Jadib on January 18th, 2010 3:24 pm under Adaptive Streaming, IIS7, Live Smooth Streaming, Media, RSCA, Smooth Streaming

    13 Comments

    Many people have been asking me how to manage publishing point programmatically on IIS Media Services 3.0 (instead of the 2.0 bits, as I explained in this post)

    So, I started to dig and I came up with the following code:

    // Live Streaming Section Path
    const string LiveStreamingSectionPath = "system.webServer/media/liveStreaming";
    
    // Change this settings with your values
    
    // Site name
    string siteName = "Default Web Site";
    // Application name
    string applicationName = "/SmoothStreaming";
    // Publishing point filename
    string fileName = "LiveSmooth.isml";
    
    ServerManager serverManager = new ServerManager();
    
    // Gets the site from IIS
    Site site = serverManager.Sites[siteName];
    
    // Gets the application from IIS
    Application application = site.Applications[applicationName];
    
    // Gets the LiveStreamingSection from the site configuration
    ConfigurationSection section = site.GetWebConfiguration().GetSection(LiveStreamingSectionPath);
    
    // Gets the ConfigurationMethodInstance to get the available publishing points
    ConfigurationMethodInstance instance = section.Methods["GetPublishingPoints"].CreateInstance();
    
    // Sets the input parameters of the GetPublishingPoints method
    instance.Input["siteName"] = site.Name;
    instance.Input["virtualPath"] = applicationName;
    
    // Executes the method
    instance.Execute();
    
    // Gets the PublishingPointCollection associated with the method output
    ConfigurationElement collection = instance.Output.GetCollection();
    
    // Looks for the publishing point and Invokes the desired method of the Publishing Point.
    // In this case we are calling the Start method (others supported functions are "Shutdown" and "Stop")
    foreach (var item in collection.GetCollection())
    {
        if (item.Attributes["name"].Value.ToString().Equals(fileName))
        {
            var method = item.Methods["Start"];
            var methodInstance = method.CreateInstance();
            methodInstance.Execute();
            break;
        }
    }

    Remember that in order to use the previous code, you must have references to the following assembly:

    • Microsoft.Web.Administration.dll (can be found at IIS Directory %windir%\System32\inetSrv)
    • Hope this helps.

    Happy streaming!

    kick it on DotNetKicks.com

    Shout it

    Tags: , , , ,

  • 13 Comments:

    1. DotNetKicks.com said on January 18, 2010:

      Live Smooth Streaming: Managing Publishing Points Programmatically on …

      You’ve been kicked (a good thing) – Trackback from DotNetKicks.com…

    2. DotNetShoutout said on January 18, 2010:

      Ezequiel Jadib’s Blog » Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media Services 3.0…

      Thank you for submitting this cool story – Trackback from DotNetShoutout…

    3. Twitter Trackbacks for Ezequiel Jadib’s Blog » Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media [southworks.net] on Topsy.com said on January 18, 2010:

      [...] Ezequiel Jadib’s Blog » Live Smooth Streaming: Managing Publishing Points Programmatically on IIS… blogs.southworks.net/ejadib/2010/01/18/live-smooth-streaming-managing-publishing-points-programmatically-on-iis-media-services-30 – view page – cached Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media Services 3.0 [...]

    4. John Deutscher said on January 18, 2010:

      Great post Ezequiel. Now a question from some encoder manufacturing friends… can you do this in C ?

    5. progg.ru said on January 19, 2010:

      Ezequiel Jadib’s Blog » Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media Services 3.0…

      Thank you for submitting this cool story – Trackback from progg.ru…

    6. John Deutscher said on January 19, 2010:

      Ezequiel,
      Have you been successful in using this code remotely with the ServerManager.OpenRemote(this.ServerName) method?

      Is there some specific configuration that needs to happen first on the box to enable the remote management?

    7. Jeremy Likness' Blog said on January 30, 2010:

      Programmatically Accessing the Live Smooth Streaming API…

      Live Smooth Streaming is a Microsoft technology that allows you to take a live, encoded, incoming video…

    8. Servefault.com said on February 6, 2010:

      Ezequiel Jadib’s Blog » Live Smooth Streaming: Managing Publishing Points Programmatically on IIS Media Services 3.0…

      Thank you for submitting this cool story – Trackback from Servefault.com…

    9. Sample script for retrieving publishing point status information - Sam Zhang's Blog : The Official Microsoft IIS Site said on November 5, 2010:

      [...] 3.0 to control the publishing point states (start/stop/shutdown). Ezequiel Jadib wrote a nice blog here showing how to use managed code to call RSCA APIs which you can reference if you want to port the [...]

    10. jlguo said on October 26, 2011:

      I meet a error when the website’s physical path set to Window Share Directory (\\10.10.10.10\path), could your help me?

    11. Parag said on November 2, 2011:

      Hi
      i am using below code to get the list of all Publishing points.
      ConfigurationMethodInstance instance = liveStreamingConfig.Methods[METHODGETPUBPOINTS].CreateInstance();

      instance.Input[ATTR_SITENAME] = siteName;
      instance.Input[ATTR_VIRTUALPATH] = applicationPath;

      instance.Execute();

      ConfigurationElement collection = instance.Output.GetCollection();

      foreach (var item in collection.GetCollection())
      {
      retVal.Add(new PublishingPoint
      {
      SiteName = siteName,
      Path = applicationPath,
      Name = item.Attributes[ATTR_NAME].Value.ToString(),
      ArchiveState = (State)item.Attributes[ATTR_ARCHIVES].Value,
      FragmentState = (State)item.Attributes[ATTR_FRAGMENTS].Value,
      StreamState = (State)item.Attributes[ATTR_STREAMS].Value,
      PubState = (PublishingPointState)item.Attributes[ATTR_STATE].Value
      });
      LogDetails(“—————————————-”);
      LogDetails(“siteName: ” + siteName);
      LogDetails(“applicationPath: ” + applicationPath);
      LogDetails(“Name: ” + item.Attributes[ATTR_NAME].Value.ToString());
      LogDetails(“ArchiveState: ” + item.Attributes[ATTR_ARCHIVES].Value.ToString());
      LogDetails(“FragmentState: ” + item.Attributes[ATTR_FRAGMENTS].Value.ToString());
      LogDetails(“StreamState: ” + item.Attributes[ATTR_STREAMS].Value.ToString());
      LogDetails(“PubState: ” + item.Attributes[ATTR_STATE].Value.ToString());
      LogDetails(“”);
      }

      But i always get the item.Attributes[ATTR_STATE].Value as zero, whatever be the state.
      can you please help me why it is not showing the correct state?

      Additionally if I click the shutdown button I get an error:
      ————————-
      Exception Details: System.Runtime.InteropServices.COMException: The data is invalid. (Exception from HRESULT: 0x8007000D)

      Source Error:

      Line 277: var method =
      item.Methods[command.ToString()];
      Line 278: var methodInstance =
      method.CreateInstance();
      Line 279: methodInstance.Execute();
      Line 280: break;
      Line 281: }

      Source File: c:\inetpub\wwwroot\MountPointHandler\Default.aspx.cs
      Line: 279
      ————————-

      Please suggest
      Thanks in advance.

      Warm Regards,
      Parag Gupta

    12. Parag said on November 3, 2011:

      Hi
      i am using below code to get the list of all Publishing points.
      ConfigurationMethodInstance instance = liveStreamingConfig.Methods[METHODGETPUBPOINTS].CreateInstance();

      instance.Input[ATTR_SITENAME] = siteName;
      instance.Input[ATTR_VIRTUALPATH] = applicationPath;

      instance.Execute();

      ConfigurationElement collection = instance.Output.GetCollection();

      foreach (var item in collection.GetCollection())
      {
      retVal.Add(new PublishingPoint
      {
      SiteName = siteName,
      Path = applicationPath,
      Name = item.Attributes[ATTR_NAME].Value.ToString(),
      ArchiveState = (State)item.Attributes[ATTR_ARCHIVES].Value,
      FragmentState = (State)item.Attributes[ATTR_FRAGMENTS].Value,
      StreamState = (State)item.Attributes[ATTR_STREAMS].Value,
      PubState = (PublishingPointState)item.Attributes[ATTR_STATE].Value
      });
      LogDetails(“—————————————-”);
      LogDetails(“siteName: ” + siteName);
      LogDetails(“applicationPath: ” + applicationPath);
      LogDetails(“Name: ” + item.Attributes[ATTR_NAME].Value.ToString());
      LogDetails(“ArchiveState: ” + item.Attributes[ATTR_ARCHIVES].Value.ToString());
      LogDetails(“FragmentState: ” + item.Attributes[ATTR_FRAGMENTS].Value.ToString());
      LogDetails(“StreamState: ” + item.Attributes[ATTR_STREAMS].Value.ToString());
      LogDetails(“PubState: ” + item.Attributes[ATTR_STATE].Value.ToString());
      LogDetails(“”);
      }

      But i always get the item.Attributes[ATTR_STATE].Value as zero, whatever be the state.
      can you please help me why it is not showing the correct state?

      Additionally if I click the shutdown button I get an error:
      ————————-
      Exception Details: System.Runtime.InteropServices.COMException: The data is invalid. (Exception from HRESULT: 0x8007000D)

      Source Error:

      Line 277: var method =
      item.Methods[command.ToString()];
      Line 278: var methodInstance =
      method.CreateInstance();
      Line 279: methodInstance.Execute();
      Line 280: break;
      Line 281: }

      Source File: c:\inetpub\wwwroot\MountPointHandler\Default.aspx.cs
      Line: 279
      ————————-

      Please suggest
      Thanks in advance.

      Warm Regards,
      Parag Gupta

    13. Zahid said on December 23, 2011:

      I’m get NullRefrence Exception on this line ” ConfigurationMethodInstance instance = section.Methods["GetPublishingPoints"].CreateInstance(); “

    Leave a comment

    Your email address will not be published.



Map

Categories