The service I was interested in consuming was the one supplied with SmarterMail installations. Consuming this API is described here and here.
I found it useful to test the procedure below out on a simple console application before I tried putting it in a module.
To start, you’ll need to know the URL of your SmarterMail installation. You can get this by just logging into your SmarterMail instance. If you don’t have a login that has administrator rights, you can stop right here because things won’t work unless you do. You should see a URL something like (only first part shown):
Your mileage may vary, but I found the root directory for the SmarterMail API Service by simply eliminating everything after the “:9998/” and adding the word “services” so the basic URL for the service looks like
This should show a listing of “asmx” files like:
These files when opened will show you information on the services available. Consider the vile svcAliasAdmin.asmx. When opened in a browser this displays (partial snipit):
To find more information out about an operation, you can click on it, but this will reveal the actual XML messages which are not needed for our purposes here. What we really want is the URL of the service we want which will be something like:
This is what we want to feed into the VS 2010 “Add Service Reference” dialog which we get when we right click on the project name and select “Add Service Reference”. Fill this in the textbox labeled “Address” and click “Go”
This should result in the svcAliasAdmin service being displayed in the “Services” box. Now go down and fill in the box at the bottom with something more meaningful than “ServiceReference1”, for example “AliasAdminService”:
Now click OK. One of the side effects of this will be to create a “system.servicemodel” section under “configuration” in your app.config or web.config. This section should be deleted as we will be doing this all from code so we don’t need to add things to the DNN site’s web.config.
First, at the top your c# file at the end of the using statements, add:
EndpointAddress endpoint =
AliasAdminService.svcAliasAdminSoapClient AliasAdmin =
new AliasAdminService.svcAliasAdminSoapClient(binding, endpoint);
var listResult = AliasAdmin.GetAliases(SMUserIDstr, SMPasswordstr, SMDomainstr);
You will note that EPAddressstr, SMUserIDstr, SMPasswordstr, and SMDomainstr have not been defined. Replace (or define them above their use) as follows:
string EPAddressstr = http://somedomain.com:9998/services/svcAliasAdmin.asmx,
SMUserIDstr = email@example.com,
SMPasswordstr = "yourpassword",
SMDomainstr = "yourdomain.com";
If you set a breakpoint after the call to “GetAliases”, then you can examine the contents of “listResult” to see if your call succeeded.
Obviously there are more parameters that are set in the automatically generated “system.servicemodel” section that you deleted from the config file, but if you are looking for a minimum starting solution, the above was a good starting point for me.
Adding this to a module was remarkable only in its simplicity. I just followed the above procedure, packaged the module, and it worked the first time I installed it on my test DNN installation. I fully expected to have to edit the manifest file and “targets” file in the BuildScripts folder to make sure the appropriate files got included in the zip and put in the right place upon installation, but, amazingly, this was not the case.