I am trying to consume the PageStoreService.asmx webserices from code using the tech note http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-60/Web-Services/
I have successfully enabled basic authentication and can browse the services through a web browser and invoke them.
I can add a web service reference to the asmx file in my visual studio project (.NET 4.0 Web application) but when I come to create an instance of the proxy object (in my instance, its named PageServiceStoreSoapClient) there are no .Credentials or .PreAuthenticate attributes for me to set for the authentication.
Looking at the generated code for the object, it inherits System.ServiceModel.ClientBase<PageStoreServiceSoap>.
This is likely more of a dot net question than specifically EPiServer.
Can anyone help? has anyone had the same issue before?
So it seems the code example from the tech note relates to how you consume this in a .NET 2.0 application - when using .NET 4.0, the classes are gerneated using the WCF way. To correctly enable this two things have to be done differnetly.1. The username and password can still be changed via code but through the .ClientCredentials Property of the soap client class. Example:
var client = new MyServiceReference.MyServiceSoapClient();
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "password";
2. The security mode needs changing from this (the default setup when adding the web refernece in .config file)
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
<transport clientCredentialType="Basic" />
In terms of the pre-authenticate (detailed in the tech note) Im not sure how that works in the 'WCF' way, but the above works successfully.
I'm trying to do the same thing but I always get the following error not matter what I try, even if the credentials are set on the proxy, my security binding changed and my user is created in the CMS admin with webservice permission checked. What Am I missing ?
Have you given the user access to the web services "Allow the user to act as a web service user" in the "Permissions to functions" (Admin > Config > Security)?
Yes. I tried many things but I didn't worked. I launched fiddler to try to figure out the problem and I don't know why but after the 1st call to the webservice (that return a 401 status, as expected), I send back the credentials for the user (crendentials are good, user is in a group that is allowed to be used as a web service user), the webservices location authorization are set properly in my web.config and even then, I still get a 401 status on the second call instead of a 200. I tried with another instance of EpiServer we have with the same client code and it works without problems.