Working with SOAP API |
Below is a step by step example on how to work with Ingeniux CMS Web Services API, via SOAP connection. We are using the most common way to consume a SOAP service, which is to add a SOAP service as a "Service Reference" in your Visual Studio Project:
Please note we are working with Visual Studio 2012 or later.
Bring up the right click Content Menu on the Visual Studio Project we are using to integrate with Ingeniux CMS Web Services API.
Add "MembershipProvidersServices.svc" reference first. It is needed to perform authentication again the Ingeniux CMS Web Services API.
Please note that the address of SOAP Service is always [your site address]/SOAP/[service name].svc.
Add the service you need to work with as reference. In this case, it is the "SiteTreeServices.svc".
Make sure the following namespaces are used:
using YourNameSpace.MembershipService; using YourNameSpace.SiteTreeServices;
Create the binding object. Ingeniux CMS SOAP API uses WSHTTPBinding in compliance to SOAP 1.2:
//token based authentication means the binding itself doesn't need to use any security mode WSHttpBinding httpBinding = new WSHttpBinding(SecurityMode.None); httpBinding.CloseTimeout = new TimeSpan(0, 1, 0); httpBinding.OpenTimeout = new TimeSpan(0, 1, 0); httpBinding.ReceiveTimeout = new TimeSpan(0, 10, 0); httpBinding.SendTimeout = new TimeSpan(0, 10, 0); httpBinding.AllowCookies = true;
Create the EndPoint to the membership providers services:
EndpointAddress endpoint = new EndpointAddress("http://[your site name]/soap/MembershipProvidersServices.svc");
Create an instance of "MembershipProvidersServicesClient", using the prepared binding object and endpoint above.
Call the "Login" method on the service client instance to retrieve the security token.
In this case, we are storing it as a variable. You could keep the token around as static field, or as cache or session data for web applications.
string token = String.Empty; using (MembershipProvidersServicesClient mservice = new MembershipProvidersServicesClient(httpBinding, endpoint)) { //membership provider name is listed under local-membership.config token = mservice.Login("[user name]", "[password]", "[Membership Provider Name]").message; }
Create the endpoint to the SiteTreeServices address:
endpoint = new EndpointAddress("http://[your site address]/soap/SiteTreeServices.svc");
Create the SiteTreeServicesClient instance, open a OperationContextScope, set the security token to the soap header, and call the site tree services' "GetChildPages" function:
using (SiteTreeServicesClient service = new SiteTreeServicesClient(httpBinding, endpoint)) { using (OperationContextScope scope = new OperationContextScope(service.InnerChannel)) { //set security token, without it the service to reject the call and return "not authenticated" error OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("IGXAToken", "IGXNameSpace", token)); //now we can call the service, to the child pages information, for folder "x2", under pub target "PublishingTargets/225" var res = service.GetChildPages( new TreeNodeInfo { objectId = "x2", widgetId = "x2", index = 0 }, "PublishingTargets/225", 0); //actual information is always the "message" property of return object PageNodeInformation[] childrenInfo = res.message; } }