Extending Commerce Server 2007 Web Services

Recently I was asked how do you extend the Commerce Server Web Services?

Commerce Server Web Services

There are four Commerce Server Web Services:

  • Profiles
  • Catalog and Inventory
  • Orders
  • Marketing

All of the Web Service can be extended as the web method are all virtual so you will need to inherit the Web Service then override any of it's methods. Here is an example of extending the Catalog Web Service.

using System;using System.Web;using System.Collections;using System.Web.Services;using System.Web.Services.Protocols;

/// <summary>/// Summary description for CatalogWebService/// </summary>[WebService(Namespace = "https://schemas.microsoft.com/CommerceServer/2006/06/CatalogWebService")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class CatalogWebService : Microsoft.CommerceServer.Catalog.WebService.CatalogWebService{    public CatalogWebService() : base() { }}

it's very important to have the namespace [WebService(Namespace = "https://schemas.microsoft.com/CommerceServer/2006/06/CatalogWebService")] otherwise calling the web methods will throw an exception. Here is an example of overriding one of the Catalog Web Service Web Method:

[WebMethod]public override Product SaveProduct(Product updatedProduct, bool forceUpdate){

    //************************************************************//    // Do some work here or after the save method   //    //************************************************************//    Product prod = base.SaveProduct(updatedProduct, forceUpdate);    return prod;}

Here is some info that might be of interest to you. We have two methods in all of our Web Services:

  • protected bool AuthorizationEnabled { get; }
    Returns true if you have Authorization Enabled in the web.config
  • protected string AuthorizationPolicyPath { get; }
    Returns the path to the Authorization Policy

You may need to add the following namespaces in order to perform additional business logic when you override Catalog Web Service methods:

  • using ADODB;
    Used by Microsoft.CommerceServer.Interop.Configuration name space if you need to access any of the Commerce Server resources the records returned are ADODB recordsets.
  • using System.Data.SqlClient;
    If you are doing custom calls to the Database then you will need this name space.
  • using Microsoft.CommerceServer.Catalog.XmlData;
    If you are going to access and modify the Product object you may require this name space.
  • using Microsoft.CommerceServer.Interop.Configuration;
    You may need this name space if you are calling any of the Commerce Resources.

Summary

So now you know how to extend the Commerce Server Web Services.