How to create your own web service in AbleCommerce
Posted: Tue May 05, 2009 2:35 pm
Did you ever want to hook AbleCommerce up to some other system?
Here's a quick tutorial on adding your own web service to AbleCommerce. The first few steps are well documented elsewhere, so I won't go into detail here.
1. Get a development copy of AbleCommerce running on a web server
2. Install Visual Studio (2005 or better) on the same server
3. Create a new solution in VS and point it to the AbleCommerce installation.
Once those steps are completed, right-click on the website of the new solution in VS, select "add a new item", and select "Web Service" . This adds the "asmx" file to the web site root folder, and the "CS" file to the App_Code folder. Now that that's in place, you can add references in the web service code-behind to .NET and CommerceBuilder as needed.
To test the web service, you'll need to set the start page in VS to the web service's "asmx" file you created above. Right-click on the "asmx" file in VS and select "Set as start page".
At this point, you can use VS's debugging tools to help you develop the web methods you need.
Once you've created web methods in the web service, there are a couple of .config settings that need to be added. In order to ensure that communications remain in HTTPS while calling the web service, the following line should be added to the "<files>" element in the ablecommerce.config file: <add path="webservice.asmx" /> Without that entry, an exception will be thrown: "Client found response content type of 'text/html' ... but expected 'text/xml'". Depending on your specific settings, you may also need to add additional lines for each web method. For example: <add path="webservice.asmx/webmethodname" />
When you're ready to roll the web service out to production, it's as simple as copying the two files to the same locations and adding the line(s) to production's ablecommerce.config.
For my own sanity, I added a parameter to the URL query string when calling the web service. If that parameter was present, the web service code would send all of its input and output to a text file while processing the XML. In order to enable the web service to read the querystring parameters, add the following lines to the <system.web> element of the web.config file:
<webServices>
<protocols>
<add name="HttpGet" />
</protocols>
</webServices>
If you don't have the resources of a development server or Visual Studio, all of the above (except for debugging, of course) can be created using Notepad.
Here's a quick tutorial on adding your own web service to AbleCommerce. The first few steps are well documented elsewhere, so I won't go into detail here.
1. Get a development copy of AbleCommerce running on a web server
2. Install Visual Studio (2005 or better) on the same server
3. Create a new solution in VS and point it to the AbleCommerce installation.
Once those steps are completed, right-click on the website of the new solution in VS, select "add a new item", and select "Web Service" . This adds the "asmx" file to the web site root folder, and the "CS" file to the App_Code folder. Now that that's in place, you can add references in the web service code-behind to .NET and CommerceBuilder as needed.
To test the web service, you'll need to set the start page in VS to the web service's "asmx" file you created above. Right-click on the "asmx" file in VS and select "Set as start page".
At this point, you can use VS's debugging tools to help you develop the web methods you need.
Once you've created web methods in the web service, there are a couple of .config settings that need to be added. In order to ensure that communications remain in HTTPS while calling the web service, the following line should be added to the "<files>" element in the ablecommerce.config file: <add path="webservice.asmx" /> Without that entry, an exception will be thrown: "Client found response content type of 'text/html' ... but expected 'text/xml'". Depending on your specific settings, you may also need to add additional lines for each web method. For example: <add path="webservice.asmx/webmethodname" />
When you're ready to roll the web service out to production, it's as simple as copying the two files to the same locations and adding the line(s) to production's ablecommerce.config.
For my own sanity, I added a parameter to the URL query string when calling the web service. If that parameter was present, the web service code would send all of its input and output to a text file while processing the XML. In order to enable the web service to read the querystring parameters, add the following lines to the <system.web> element of the web.config file:
<webServices>
<protocols>
<add name="HttpGet" />
</protocols>
</webServices>
If you don't have the resources of a development server or Visual Studio, all of the above (except for debugging, of course) can be created using Notepad.