This topic contains a small example for a SVC. web service call with claims based authentication from ISHSTS which is the out-of-the-box STS for internal Content Manager 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 on September 2013 using the following prerequisites:
- Microsoft .NET FrameWork
- Microsoft Visual Studio
-
Web service URL
-
Make sure you know the full URL to the
Content Manager web services which is a combination of the following input parameters:
baseurl containing something like https://ish.example.com (or http://ish.example.com) where ish refers to an example server dedicated to Content Manager.
infosharewswebappname which contains the name of the website for the Content Manager web service (e.g. ISHWS)
This URL (e.g. https://ish.example.com/ISHWS) 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 Content Manager components and the metadata for the logged in user when your system is configured to use the out-of-the-box ISHSTS. The example is based on username/password authentication but extra remarks are present to change to windows authentication.
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://ish.example.com/ISHWS/Wcf/API25/application.svc
- Enter in the Namespace, the value
Application25ServiceReference
The Visual Studio code generator will create the necessary classes for the proxy but also the app.config. In this file the issue/wstrust/mixed/username has been automatically chosen. This endpoint is used for username/password driven authentication
- If you want windows authentication then
- Open the
app.config file
- Goto
CustomBinding_Application binding (on top) locate the issuedTokenParameters node and replace the full issuer node with the correct issuer. Normally the other endpoints are available in commented form in the configuration as <alternativeIssuedTokenParameters>. Locate and copy the right issuer endpoint for binding ws2007HttpBinding.
For this example we used the issuer that has a binding configuration for issue/wstrust/mixed/windows.
- Repeat previous step for
CustomBinding_Application1
- 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://ish.example.com/ISHWS/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 Content Manager 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://ish.example.com/ISHWS/Wcf/API25/Application.svc"
binding="customBinding" bindingConfiguration="CustomBinding_Application"
contract="Application25ServiceReference.Application" name="CustomBinding_Application" />
<endpoint address="https://ish.example.com/ISHWS/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/ISHWS/Wcf/API25/Application.svc and contract Application25ServiceReference.Application
- One endpoint with
address WebServiceURL/ISHWS/Wcf/API25/User.svc and contract User25ServiceReference.User
- Inside the code, you should now be able to write something such as:
Note: Depending on the issuer that was chosen in the app.config you need to drive the authentication in the code. To use windows authentication, you need to comment out the parts that provide credentials.
using System;
using System.ServiceModel;
using System.Text;
namespace MyMetadataWithInfoShareSTS
{
class Program
{
static void Main(string[] args)
{
//Username/Password authentication. Comment out for windows authentication.
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();
//Username/Password authentication. Comment out for windows authentication.
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();
}
}
}
}