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.
Comments
Anonymous
November 20, 2006
The comment has been removedAnonymous
November 20, 2006
The comment has been removedAnonymous
November 28, 2006
So far we have figured out our requirements and created a design out of that. In the last post we createdAnonymous
April 02, 2007
Max, Do you think we'll be seeing a Commerce Server 2007 reference book from Microsoft Press, or Wrox, or Apress any time soon??? Thanks! GlenAnonymous
April 03, 2007
Yes, Wade is working with Wrox to get a book out soon. Take a look at this link http://blogs.msdn.com/maxakbar/archive/2007/03/23/commerce-server-training-part-ii.aspx -MaxAnonymous
August 26, 2007
How about everything :)! Integrating a Custom Snap-in Extension Developing with Resources Using Pup toAnonymous
October 12, 2007
Hi Max I would like to extend the profilewebservice and for that Can I use a custom namespace while inheriting from the profilewebservice? Given Namespace http://schemas.microsoft.com/CommerceServer/2006/03/ProfileWebService Can I have something like the following [a] "http://schemas.microsoft.com/CommerceServer/2006/03/myProfileWebService/" or [b] "http://schemas.microsoft.com/CommerceServer/2006/03/ProfileWebService/01/" Thanks a bunch for your help. Regards Bhaskar VenkataAnonymous
October 15, 2007
Hi Max, Sometimes, we will use the images in both catelog and profile system(such as userprofile or organization photo), so do you think that we'd better use a separated database to store the image info instead of the catalog db? Many thanks!Anonymous
October 30, 2007
Yup, I would keep the images seperate. -MaxAnonymous
October 30, 2007
you ca try to rename the web service but I don't recomend it. Why do you want to change the namespace? -MaxAnonymous
January 11, 2008
I would like to customize the profile web service for ex. currenltly there is no login web method present in profile web service and I want to add it. Please let me know how to achieve it. Thanks, Anup DharamthokAnonymous
January 11, 2008
I am not sure what you mean about a login method. Do you mean that you want to use the Profile Web Service to authenticate web site users? -MaxAnonymous
January 14, 2008
Yes. Consider for example I want to add one more webmethod in exisitng profileswebservice because of custom requirements. Please let me know how to do it.Anonymous
January 14, 2008
The comment has been removedAnonymous
January 15, 2008
Thank you very much. The scenario is that our company has Profile web service developed using CS2002 and would like to upgrade it to CS2007. If I'll use existing CS2007 ProfilesWebService.asmx then it can't provide me all the methods which exist in our company Profile.asmx. Could you please suggest best solution to solve this problem because the existing company profile.asmx is used across multiple applications and its very difficult to change the webmethods used in each applicaiton hence i'm thinking to use the ProfilesWebService.asmx and extend all those webhods.Anonymous
January 17, 2008
You can just put the profile.asmx in the same folder as the ProfilesWebService.asmx then just change the url for the web service connection. Having a small view of your requirement I can’t recommend much :(. Good luck, -MaxAnonymous
January 20, 2008
Thanks. As per your suggetion I have created the Profile.asmx also changed the service connection in customer and order manager but its throwing an error "An unexpected error accured. If problem persist then contact you radministrator". I have looked into the event log folder and found following details... "System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://schemas.microsoft.com/CommerceServer/2006/03/ProfilesWebService/GetAllProfileDefinitionNames. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) at Microsoft.CommerceServer.ServiceAgent.TryHandleWebMethodException(Exception ex, SoapHttpClientProtocol serviceProxy) at Microsoft.CommerceServer.Internal.Profiles.ProfilesServiceProxy.AuthorizedInvoke(String methodName, Object[] parameters) at Microsoft.CommerceServer.Internal.Profiles.ProfilesServiceProxy.GetAllProfileDefinitionNames() at Microsoft.CommerceServer.Profiles.ProfileManagementContext.GetAllProfileDefinitionNames() at Microsoft.CommerceServer.UI.CustomerAndOrdersManager.ProfilesManagementProxy.TryGetAllProfileDefinitionNames(String[]& profileTypes)". I have given the right permission also configured web.cong correctly but still I'm getting the error.Could you please let me know where I went wrong. Thanks, AnupAnonymous
January 21, 2008
Are you saying that you just added a new profile web service and pointed the connection string to that new web service? If so then this will not work. I should have been clear when I said that you can added a new web service to the same directory but don't expect the "Customer and Orders Manager" to work by pointing to this new Web Service. "Customer and Orders Manager" doesn't understand anything about the new Web Service. What I was intending for you by adding you new web service was that you can point your other applications to this url. -MaxAnonymous
January 21, 2008
Thank you very much for your extended co-opration. Ok I'll point new web service to other application. One more question I have added new profile defination in profile Catalog called CustomerAccountNumber and also created new table in database as well as in Data source because i would like to customize the profile system. When I'm accessing this new profile defination at Runtime from source code it is throwing an error "Falied to retrive Profile" though I have configured everthing. The details as given below Web.Config extended " <caProfile profileDefinition="CustomerAccountNumber" userIdProperty="GeneralInfo.GeneralInfo.customer_account_number"/>" Source Code details ProfileContext profiles = CommerceContext.Current.ProfileSystem; Profile profile = null; string keyName = "GeneralInfo.customer_account_number"; string keyValue = "11111111"; profile = profiles.GetProfile(keyName, keyValue, "CustomerAccountNumber"); (At this point it is throwing an error, I have tried all possibilities but still keeps on getting same error.Please me know Do i need to set any thing more? Thanks, AnupAnonymous
January 21, 2008
Thank you very much for your extended co-opration. Ok I'll point new web service to other application. One more question I have added new profile defination in profile Catalog called CustomerAccountNumber and also created new table in database as well as in Data source because i would like to customize the profile system. When I'm accessing this new profile defination at Runtime from source code it is throwing an error "Falied to retrive Profile" though I have configured everthing. The details as given below Web.Config extended " <caProfile profileDefinition="CustomerAccountNumber" userIdProperty="GeneralInfo.customer_account_number"/>" Source Code details ProfileContext profiles = CommerceContext.Current.ProfileSystem; Profile profile = null; string keyName = "GeneralInfo.customer_account_number"; string keyValue = "11111111"; profile = profiles.GetProfile(keyName, keyValue, "CustomerAccountNumber"); (At this point it is throwing an error, I have tried all possibilities but still keeps on getting same error.Please me know Do i need to set any thing more? Sorry previous post by mistake I typed userIdProperty="GeneralInfo.GeneralInfo.customer_account_number which should be userIdProperty="GeneralInfo.customer_account_number Thanks, AnupAnonymous
January 22, 2008
The comment has been removedAnonymous
January 22, 2008
Thanks. In my case the CustomerAccountNumber is a profile defination hence i'm calling GetProfile using profiles.GetProfile(keyName, keyValue, "CustomerAccountNumber"); But no problem I have solved the problem it was because i have not provided proper permissions to CustomerAccountNumber table in SQL database. Thanks,Anonymous
January 22, 2008
Ah, that would do it :). -MaxAnonymous
January 22, 2008
Can we use commerce server 2007 with .net 3 or .net 3.5 ? Because I had read in document that Commerce Server 2007 doesn't support the current .NET 3.0 Framework. Thanks, AnupAnonymous
January 29, 2008
Anser to .NET 3.5 and CS2007: I have heard of customers who have done this with no issues but if you are going to deploy a critical enterprise application I would ping PSS folks. I know this is pretty mush generic answer but I wouldn’t want to give bad advice :). Anser to .NET 3.0 and CS2007: As for as I know the only thing that got changed in the .NET 3.0 was some addition like Communication and Workflow. Most of the objects that CS2007 works with is System.Data and System.Xml. I don't think this was in the documentation about not supporting the .NET framework but then again contact PSS for a formal answer. -MaxAnonymous
January 30, 2008
Use something like Fiddler to find the webservice namespace, eg. http://schemas.microsoft.com/CommerceServer/2006/06/CatalogWebService http://schemas.microsoft.com/CommerceServer/2006/03/ProfilesWebServiceAnonymous
January 31, 2008
Yes and reflector is your best friend :). -MaxAnonymous
March 19, 2008
How to get the connection string that the web service is using while serving the requests ?Anonymous
March 19, 2008
The web.config of teh Web Services has a site name you would read the site name and get a collection of resources then you would need to figure out what type of web service you are in and then get the connection string from the resources collection. -Max