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

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

    14 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: , , , ,

    • John Deutscher

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

    • John Deutscher

      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?

    • http://www.collegetvticket.com Dennis Jacobs

      Dear Mr. Jadib:

      John Deutscher suggested that we get in touch with you regarding the inability of Expression 4 to resume publishing on an IIS server after a disconnect from that point.

      We need something simple and as automatic as possible. Our company helps small colleges webcast their sports over the internet. Connections often fail and we need a way for them to click on the “start” button of Expression 4 to resume the webcast. There is noone to monitor and manually restart the publishing points.

      We do have the “restartOnEncoderReconnect” installed and have tried the newest encoder build (11-18) but it failed.

      If you can give us some code to be pasted somewhere or create a separate “restart” application web page that our college students can use, it would be very appreciated.

      Also please give me an idea of what your services would cost for this.

      Thank you,

      Dennis Jacobs
      214-363-9595
      dj@collegetvticket.com

    • jlguo

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

    • Parag

      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

    • Parag

      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

    • Zahid

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



Map

Categories