Friday, January 6, 2012

Ektron: "System.Web.Services.Protocols.SoapException: Credentials must be specified"

When using the Ektron.Services a feature works correctly, but when deployed to a remote machine, the content rendering fails with "System.Web.Services.Protocols.SoapException: Credentials must be specified".


Server Error in '/' Application.
--------------------------------------------------------------------------------

Credentials must be specified
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Services.Protocols.SoapException: Credentials must be specified

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Ouch.

According to this post System.Web.Services.Protocols.SoapException: Credentials must be specified "That code will work from local system but won't work from remote system because of security. Ektron does not allow unauthenticated remote calls. In order to execute WS calls remotely you need to specify username and password of a cms user."

This code will add authentication that will allow the call to complete without a SOAP exception:
Ektron.Services.AuthenticationHeaderValue = new Ektron.Services.AuthenticationHeader();
Ektron.Services.AuthenticationHeaderValue.Username = "admin";
Ektron.Services.AuthenticationHeaderValue.Password = "admin";

This is a great example where you could wrap the authentication into a factory for creation of the service wrapper objects and/or create a fluent extension method that sets credentials for each wrapper object:
var taxonomySvc = TaxonomyFactory.GetService(); OR var taxonomySvc = new Ektron.Services.Taxonomy().WithDefaultCredentials();

However, you should not a couple of things.

In my case, I was working with the Taxonomy classes, and by accident referenced: Ektron.Services.Taxonomy and NOT Ektron.Cms.API.Content.Taxonomy. Apparently they both work the same, and are available (in separate namespaces). According to the same post, the latter (Ektron.Cms.API.Content.Taxonomy) should not require credentials. Which would explain how I came across this problem in the first place.

References:
System.Web.Services.Protocols.SoapException: Credentials must be specified

No comments: