Documentation Center

Using .SVC Web Service in C# for ADFS

This topic contains a small example for a SVC. web sevice call with claims based authentication using ADFS

Before you begin

Prerequisites
This working example was created 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. http://ish.example.com/ISHWS) is referenced below 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 ADFS and windows authentication.

Procedure

  1. Create a Visual Studio Project, for example, a Console Application.
  2. Navigate to the project then right click on References section.
  3. Add a web service reference to the Application25 web service:
    1. Select Add Service Reference...
    2. In the Adress text box type the WebServiceURL followed by /Wcf/API25/application.svc
      For example: http://ish.example.com/ISHWS/Wcf/API25/application.svc
    3. Enter in the Namespace, the value Application25ServiceReference
  4. If the relying party's policy of the STS contains multiple issuer endpoints without specifying which issuer endpoint to use, one of the endpoints is selected as the issuer endpoint to use. Check the configuration to ensure that the right issuer endpoint was selected.
    1. Open the app.config file
    2. 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 13/windowsmixed.

    3. Repeat previous step for CustomBinding_Application1
  5. Add a web service reference to the User25 web service:
    1. Select Add Service Reference...
    2. In the Adress text box, enter the WebServiceURL followed by /Wcf/API25/user.svc
      For example: http://ish.example.Com/ISHWS/Wcf/API25/user.svc
    3. Enter in the Namespace, the value User25ServiceReference
  6. Open the app.config file.
  7. Check that there is exactly one endpoint for each web service reference
    1. 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" />
    2. 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
  8. Inside the code you should now be able to write something such as:
    using System;
    using System.ServiceModel;
    using System.Text;
    
    namespace MyMetadataWithAFDS
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    // Create proxy instance
                    Application25ServiceReference.ApplicationClient applicationClient = new Application25ServiceReference.ApplicationClient();
    
                    // Optionally specify manual credentials
                    //applicationClient.ClientCredentials.Windows.ClientCredential.Domain = Domain;
                    //applicationClient.ClientCredentials.Windows.ClientCredential.UserName = UserName;
                    //applicationClient.ClientCredentials.Windows.ClientCredential.Password = Password;
    
                    // Execute the GetVersion call
                    string version = applicationClient.GetVersion();
    
                    Console.WriteLine(version);
    
                    // Create proxy instance
                    User25ServiceReference.UserClient userClient = new User25ServiceReference.UserClient();
    
                    // Optionally specify manual credentials
                    //userClient.ClientCredentials.Windows.ClientCredential.Domain = Domain;
                    //userClient.ClientCredentials.Windows.ClientCredential.UserName = UserName;
                    //userClient.ClientCredentials.Windows.ClientCredential.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();
                }
            }
        }
    }