Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

InfoPath with Microsoft Content Management Server Web Services : Creating the ASP.NET Web Service

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
8/17/2012 6:14:09 PM
We will now create an ASP.NET Web service (.asmx) to encapsulate our Web methods. The first Web method, GetPosting(), will return a serialized LightweightPosting object and during serialization the properties and public fields will be serialized and nested in the XML. The second Web method, SavePosting(), will accept a LightweightPosting and call the Save() method to update MCMS.

To create the ASP.NET Web service, perform the following steps:

1.
In Visual Studio .NET, right-click on the McmsAuthoringWebService project and select Add | Add Web Service.

2.
Name this Web service Authoring.asmx and click OK.

3.
Click on the Click Here link to switch to code view.

4.
Add the following namespaces to the file:

using System.Security.Principal;
using Microsoft.ContentManagement.Publishing;

5.
Delete the following code as we will not be needing it:

// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5

//    [WebMethod]
//    public string HelloWorld()
//    {
//      return "Hello World";
//    }

The GetPosting() Web Method

Now let’s define our GetPosting() Web method that will populate one of our custom LightweightPosting objects from MCMS. For GetPosting() to be accessible via a Web service it must have the [WebMethod] attribute. If the strPath parameter is an empty string we will initialize an empty LightweightPosting object so the complete object model is serialized.

/// <summary>
/// Gets a Lightweight posting and all the properties by path
/// </summary>
/// <param name="strPath">Path of the posting</param>
/// <returns>LightweightPosting</returns>
[WebMethod]
public LightweightPosting GetPosting(string strPath)
{
  // Did we pass in a path?
  if (strPath == "")
  {
    // Define a lightweight posting object
    LightweightPosting _LightweightPosting = new LightweightPosting();

    // Initialize the Custom Properties, Placeholders and Template
    _LightweightPosting.CustomProperties =
             new LightweightCustomPropertyCollection();
    _LightweightPosting.Placeholders =
             new LightweightPlaceholderCollection();
    _LightweightPosting.Template = new LightweightTemplate();

    // Create an empty placeholder
    LightweightPlaceholder _placeHolder = new LightweightPlaceholder();

    // Load an empty string into the Value property
    _placeHolder.Value = _placeHolder.LoadXHTML("");

    // Add the placeholder to the collection
    _LightweightPosting.Placeholders.Add(_placeHolder);

    // Return the posting object
    return(_LightweightPosting);
  }
  else
  {
    // Declare a Posting object
    Posting _Posting = null;

    // Create the new application context
    CmsApplicationContext cmsContext = new CmsApplicationContext();

    // We need to get the identity of the current user
    WindowsIdentity ident = System.Web.HttpContext.Current.User.Identity
                         as WindowsIdentity;

    try
    {
      // Authenticate into update mode
      cmsContext.AuthenticateUsingUserHandle(ident.Token,
            PublishingMode.Update);
    }
    catch(Exception ex)
    {
      // Dispose of the CMS Context
      cmsContext.Dispose();

      throw new Exception("Failed to Authenticate user by handle. "
                        + "The user may not have author permissions.", ex);
    }

    // Get the MCMS Posting object by path
    _Posting = (Posting)cmsContext.Searches.GetByPath(strPath);

    // Verify the posting was found
    if (_Posting == null)
    {
      // Dispose the CMS Context
      cmsContext.Dispose();

      throw new Exception("The posting was not found at path '"
                         + strPath + "'");
    }

    // Instantiate the lightweight posting passing
    // in the MCMS posting to the constructor.
    LightweightPosting _LightweightPosting = new LightweightPosting(_Posting);

    // Dispose the CMS Context
    cmsContext.Dispose();

    // Return the lightweight posting
    return(_LightweightPosting);
  }
}

					  

Configuring IIS Security

As we are using the current user’s Windows identity to authenticate the CmsApplicationContext, we should verify anonymous access to this Web service is disabled.

1.
In the web.config file, verify the authentication element is set to: <authentication mode=“Windows” />

2.
In the Internet Information Services (IIS) management console, right-click on the McmsAuthoringWebService virtual directory and select Properties.

3.
Select the Directory Security tab.

4.
Under Anonymous access and authentication control, select Edit.

5.
Uncheck Anonymous access and check Integrated Windows authentication.

6.
Click OK and close all opened dialogs.

7.
Close the IIS management console.

Testing the Web Service

To test it out, we can set the Web service as the start page for the project by right-clicking on authoring.asmx in Solution Explorer, and selecting Set As Start Page. Then start without debugging by pressing Control-F5 or selecting Start Without Debugging from the Debug menu.

We should now see the ASP.NET Web service test page, listing GetPosting as the single available Web method:

If you now click on GetPosting, you will see a textbox for the parameter strPath. Enter /channels/www.tropicalgreen.net/PlantCatalog/AloeVera into the box and click Invoke.

You will now see the serialized view of the LightweightPosting object and all its serializable properties:

The SavePosting() Web Method

Let’s create another Web method, SavePosting(), which will accept a LightweightPosting object as a parameter and save its contents to MCMS. Add the following code to the authoring.asmx.cs file and rebuild the solution:

/// <summary>
/// Save a lightweight posting object to MCMS
/// </summary>
/// <param name="_Posting">LightweightPosting object to save</param>
[WebMethod]
public void SavePosting(LightweightPosting _Posting)
{
  // Save the posting
  _Posting.Save();
}

The SavePosting() Web method cannot be tested from the browser as we did for GetPosting() as it requires a complex datatype (LightweightPosting) as a parameter. We will test SavePosting() via the InfoPath form we will create shortly.

Other -----------------
- Active Directory Domain Services 2008 : Configuring Attributes to Be Indexed for Containerized Searches, Configuring Attributes Not to Be Indexed for Containerized Searches
- Active Directory Domain Services 2008 : Configure Attributes to Be Copied When Duplicating Users, Configure Attributes Not to Be Copied When Duplicating Users
- Windows Server 2008 Server Core : Associating a Folder to a Drive with the Subst Utility, Displaying a Directory Structure with the Tree Utility, Managing the Volume Shadow Service with the VSSAdmin U
- Microsoft Dynamic GP 2010 : Module Setup - Inventory (part 3) - Inventory Item Setup
- Microsoft Dynamic GP 2010 : Module Setup - Inventory (part 2) - Item class setup
- Microsoft Dynamic GP 2010 : Module Setup - Inventory (part 1) - Inventory Control Setup, Inventory sites, Unit of Measure Schedules
- Exchange Server 2007 : Designing Exchange Infrastructure, Integrating Client Access into Exchange Server 2007 Design
- Exchange Server 2007 : Designing Exchange Server Roles in an Exchange Environment
- Microsoft Dynamics CRM 4.0 : Infrastructure Design Considerations - Outlook Infrastructure Optimization
- Microsoft Dynamics CRM 4.0 : Infrastructure Design Considerations - Office Communication Server Setup
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server