This topic contains a small example for a SVC. web sevice call with claims based authentication from InfoShareSTS which is the out-of-the-box STS for internal SDL LiveContent Architect users
Before you begin
Important: This information is provided as is without guarantees. Any feedback or corrections are appreciated.
-
Prerequisites
-
This working example was created November 2012 using the following prerequisites:
- Microsoft .NET FrameWork 4.0
- Microsoft Visual Studio 2010
-
Web service URL
-
Make sure you know the full URL to the InfoShare web services which is a combination of the following input parameters:
baseurl containing something like https://serveradress (or http://serveradress)
infosharewswebappname which contains the name of the website for the InfoShare web service (e.g. InfoShareWS, InfoShareWSDita,...)
This URL (e.g. https://serveradress/InfoShareWS) will be referred as WebServiceURL
About this task
This example describes how to make 2 WCF SVC. web service calls to get the version of the InfoShare components and the metadata for the logged in user when your system is configured to use the out-of-the-box InfoShareSTS which uses user name and password to authenticate an internal SDL LiveContent Architect user.
Procedure
- Create a Visual Studio Project, for example, a Console Application
- Navigate to the project and right click References section.
- Add a web service reference to the
Application25 web service:
- Select Add Service Reference...
- In the Address text box type the
WebServiceURL followed by /Wcf/API25/application.svc
For example: "https://serveradress/InfoShareWS/Wcf/API25/application.svc"
- Enter in the Namespace, the value
Application25ServiceReference
- Add a web service reference to the
User25 web service.
- Select Add Service Reference...
- In the Adress text box type the
WebServiceURL followed by /Wcf/API25/user.svc
For example: "https://serveradress/InfoShareWS/Wcf/API25/user.svc"
- Enter in the Namespace, the value
User25ServiceReference
- Open the
app.config file.
- Check that there is exactly one
endpoint for each web service reference
- The InfoShare web services are available via
http and https. Regardless of the choice you made in the WebServiceURL both endpoints are present in the app.config. Remove the endpoint which does not match your WebServiceURL.
<endpoint address="http://serveradress/InfoShareWS/Wcf/API25/Application.svc"
binding="customBinding" bindingConfiguration="CustomBinding_Application"
contract="Application25ServiceReference.Application" name="CustomBinding_Application" />
<endpoint address="https://serveradress/InfoShareWS/Wcf/API25/Application.svc"
binding="customBinding" bindingConfiguration="CustomBinding_Application1"
contract="Application25ServiceReference.Application" name="CustomBinding_Application1" />
- Check that there is an endpoint for both web services
The endpoint for a second web service reference is not always added automatically. If the endpoint is missing, copy the chosen endpoint of the other web service and correct the address and the contract to match the missing endpoint.
Resulting in the following 2 endpoints:
- One endpoint with
address WebServiceURL/InfoShareWS/Wcf/API25/Application.svc and contract Application25ServiceReference.Application
- One endpoint with with
address WebServiceURL/InfoShareWS/Wcf/API25/User.svc and contract User25ServiceReference.User
- Inside the code, you should now be able to write something such as:
using System;
using System.ServiceModel;
using System.Text;
namespace MyMetadataWithInfoShareSTS
{
class Program
{
static void Main(string[] args)
{
string userName = "admin";
string password = "admin";
try
{
// Create proxy instance
Application25ServiceReference.ApplicationClient applicationClient = new Application25ServiceReference.ApplicationClient();
applicationClient.ClientCredentials.UserName.UserName = userName;
applicationClient.ClientCredentials.UserName.Password = password;
// Execute the GetVersion call
string version = applicationClient.GetVersion();
Console.WriteLine(version);
// Create proxy instance
User25ServiceReference.UserClient userClient = new User25ServiceReference.UserClient();
userClient.ClientCredentials.UserName.UserName = userName;
userClient.ClientCredentials.UserName.Password = password;
// Create requested metadata xml
string xmlRequestedMetadata = "<ishfields>" +
"<ishfield name='USERNAME' level='none'/>" +
"<ishfield name='FISHUSERDISPLAYNAME' level='none'/>" +
"<ishfield name='FISHEMAIL' level='none'/>" +
"<ishfield name='FUSERGROUP' level='none'/>" +
"<ishfield name='FISHUSERROLES' level='none' ishvaluetype='element'/>" +
"<ishfield name='FISHEXTERNALID' level='none'/>" +
"</ishfields>";
// Execute the GetMyMetadata call
string xmlObjectList = userClient.GetMyMetadata(xmlRequestedMetadata);
Console.WriteLine(xmlObjectList);
}
//Catch all Application25 server exceptions that are generated after the request has been validated on the server and executes.
catch (FaultException<Application25ServiceReference.InfoShareFault> fex)
{
Console.WriteLine("API25 FaultException: {0}",fex);
Console.WriteLine("Action: {0}", fex.Action);
Console.WriteLine("Reason: {0}", fex.Reason);
Console.WriteLine("Description: {0}", fex.Detail.Description);
Console.WriteLine("InfoShareErrorNumber: {0}", fex.Detail.InfoShareErrorNumber);
Console.WriteLine("Origin: {0}", fex.Detail.Origin);
Console.WriteLine("XMLDetail: {0}", fex.Detail.XMLDetail);
}
//Catch all User25 server exceptions that are generated after the request has been validated on the server and executes.
catch (FaultException<User25ServiceReference.InfoShareFault> fex)
{
Console.WriteLine("User25 FaultException: {0}", fex);
Console.WriteLine("Action: {0}", fex.Action);
Console.WriteLine("Reason: {0}", fex.Reason);
Console.WriteLine("Description: {0}", fex.Detail.Description);
Console.WriteLine("InfoShareErrorNumber: {0}", fex.Detail.InfoShareErrorNumber);
Console.WriteLine("Origin: {0}", fex.Detail.Origin);
Console.WriteLine("XMLDetail: {0}", fex.Detail.XMLDetail);
}
//Catch all server exception that are generated before the request has been validated on the server and executes.
//e.g. Token validation
catch (FaultException fex)
{
Console.WriteLine("FaultException: {0}", fex);
Console.WriteLine("Action: {0}", fex.Action);
Console.WriteLine("Reason: {0}", fex.Reason);
}
//Catch the test
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex);
}
finally
{
Console.WriteLine("Press any key...");
Console.ReadLine();
}
}
}
}