Using Programmatic Binding with FIM Client for use with UPN/SPN

Jun 22, 2012 at 4:43 PM

I have added a few constructors and utility methods to allow for programmatic bindings to the FIM service endpoints when the client is executing remotely from the FIM services. This allows the endpoint bindings to use a UPN/SPN, depending on delegation you have defined.

The CreateWSHttpBinding methods could be factored out into a separate class allowing the hard-coded values to be configurable as public properties.

Hopeful that this will help others struggling with this type of client configuration.

 

 

// Variables to hold the input Service URL and User Principle Name
private String serviceURL = "";
private String userPrincipleName = "";

// Constructor using Programmatic Bindings and DefaultNetworkCredentials
public DefaultClient(
    string serviceURL, 
    string userPrincipleName)
    : this(
        CredentialCache.DefaultNetworkCredentials, 
        serviceURL, 
        userPrincipleName) 
{
}

// Constructor using Programmatic Bindings with specified NetworkCredentials
public DefaultClient(
    NetworkCredential clientCredential, 
    string serviceURL, 
    string userPrincipleName)
{
    // Set the service URL and Principle Name
    this.userPrincipleName = userPrincipleName;

    // Make sure there is a trailing slash "/"
    if (serviceURL.EndsWith("/"))
        this.serviceURL = serviceURL;
    else
        this.serviceURL = serviceURL + "/";

    // Create the Objects we need for this client
    this.wsTransferClient = new WsTransferClient(CreateWSHttpContextBinding("ServiceMultipleTokenBinding_Resource"), 
						CreateEndpointAddress(this.serviceURL, "Resource", this.userPrincipleName));
    this.wsTransferFactoryClient = new WsTransferFactoryClient(CreateWSHttpContextBinding("ServiceMultipleTokenBinding_ResourceFactory"), 
							       CreateEndpointAddress(this.serviceURL, "ResourceFactory", this.userPrincipleName));
    this.wsEnumerationClient = new WsEnumerationClient(CreateWSHttpContextBinding("ServiceMultipleTokenBinding_Enumeration"), 
							CreateEndpointAddress(this.serviceURL, "Enumeration", this.userPrincipleName));
    this.mexClient = new MexClient(CreateWSHttpBinding("MetadataExchangeHttpBinding_IMetadataExchange"), 
							CreateEndpointAddress("MEX"));

    this.resourceFactory = new RmResourceFactory();
    this.requestFactory = new RmRequestFactory();
	
	this.ClientCredential = clientCredential;
}

/// <summary>
/// Create a new WSHttpBinding
/// </summary>
/// <param name="ContextName">name of binding</param>
/// <returns>WSHttpBinding</returns>
private static WSHttpBinding CreateWSHttpBinding(string ContextName)
{
	// ToDo: Refactor as a new class. Replace hard-coded values with public properties.
    WSHttpBinding oMetadataExchangeHttpBinding = new WSHttpBinding();
    oMetadataExchangeHttpBinding.Name = ContextName;
    oMetadataExchangeHttpBinding.CloseTimeout = new TimeSpan(0, 1, 0);
    oMetadataExchangeHttpBinding.OpenTimeout = new TimeSpan(0, 1, 0);
    oMetadataExchangeHttpBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
    oMetadataExchangeHttpBinding.SendTimeout = new TimeSpan(0, 1, 0);
    oMetadataExchangeHttpBinding.BypassProxyOnLocal = false;
    oMetadataExchangeHttpBinding.TransactionFlow = false;
    oMetadataExchangeHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
    oMetadataExchangeHttpBinding.MaxBufferPoolSize = 524288;
    oMetadataExchangeHttpBinding.MaxReceivedMessageSize = 965536;
    oMetadataExchangeHttpBinding.MessageEncoding = WSMessageEncoding.Text;
    oMetadataExchangeHttpBinding.TextEncoding = Encoding.UTF8;
    oMetadataExchangeHttpBinding.UseDefaultWebProxy = true;
    oMetadataExchangeHttpBinding.AllowCookies = false;
    oMetadataExchangeHttpBinding.ReaderQuotas = new XmlDictionaryReaderQuotas();
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxDepth = 32;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxStringContentLength = 8192;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxArrayLength = 16384;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
    oMetadataExchangeHttpBinding.ReliableSession.Ordered = true;
    oMetadataExchangeHttpBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
    oMetadataExchangeHttpBinding.ReliableSession.Enabled = false;
    oMetadataExchangeHttpBinding.Security.Mode = SecurityMode.None;
    oMetadataExchangeHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    oMetadataExchangeHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
    oMetadataExchangeHttpBinding.Security.Transport.Realm = "";
    oMetadataExchangeHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    oMetadataExchangeHttpBinding.Security.Message.NegotiateServiceCredential = true;
    oMetadataExchangeHttpBinding.Security.Message.EstablishSecurityContext = true;
    return oMetadataExchangeHttpBinding;
}

/// <summary>
/// Create a new WSHttpContextBinding
/// </summary>
/// <param name="ContextName">name of binding</param>
/// <returns>WSHttpContextBinding</returns>
private static WSHttpContextBinding CreateWSHttpContextBinding(string ContextName)
{
	// ToDo: Refactor as a new class. Replace hard-coded values with public properties.
    WSHttpContextBinding oContextBinding = new WSHttpContextBinding();
    oContextBinding.Name = ContextName;
    oContextBinding.CloseTimeout = new TimeSpan(0, 1, 0);
    oContextBinding.OpenTimeout = new TimeSpan(0, 1, 0);
    oContextBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
    oContextBinding.SendTimeout = new TimeSpan(0, 1, 0);
    oContextBinding.BypassProxyOnLocal = false;
    oContextBinding.TransactionFlow = false;
    oContextBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
    oContextBinding.MaxBufferPoolSize = 524288;
    oContextBinding.MaxReceivedMessageSize = 2621440;  // This needs to be configurable!!!
    oContextBinding.MessageEncoding = WSMessageEncoding.Text;
    oContextBinding.TextEncoding = Encoding.UTF8;
    oContextBinding.UseDefaultWebProxy = true;
    oContextBinding.AllowCookies = false;
    oContextBinding.ContextProtectionLevel = System.Net.Security.ProtectionLevel.Sign;
    oContextBinding.ReaderQuotas = new XmlDictionaryReaderQuotas();
    oContextBinding.ReaderQuotas.MaxDepth = 32;
    oContextBinding.ReaderQuotas.MaxStringContentLength = 8192;
    oContextBinding.ReaderQuotas.MaxArrayLength = 16384;
    oContextBinding.ReaderQuotas.MaxBytesPerRead = 4096;
    oContextBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
    oContextBinding.ReliableSession.Ordered = true;
    oContextBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
    oContextBinding.ReliableSession.Enabled = false;
    oContextBinding.Security.Mode = SecurityMode.Message;
    oContextBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    oContextBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
    oContextBinding.Security.Transport.Realm = "";
    oContextBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    oContextBinding.Security.Message.NegotiateServiceCredential = true;
    oContextBinding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
    oContextBinding.Security.Message.EstablishSecurityContext = false;
    return oContextBinding;
}

/// <summary>
/// Create and endpoint address based on endpointname.
/// </summary>
/// <param name="EndPointName">Name of the service endpoint</param>
/// <returns>EndpointAddress</returns>
private EndpointAddress CreateEndpointAddress(string EndPointName)
{
    return CreateEndpointAddress(this.serviceURL, EndPointName, this.userPrincipleName);
}
/// <summary>
/// Create and endpoint address based on service URL and endpointname.
/// </summary>
/// <param name="ServiceURL">Path to the server services root.</param>
/// <param name="EndPointName">Name of the service endpoint</param>
/// <returns>EndpointAddress</returns>
private EndpointAddress CreateEndpointAddress(string ServiceURL, string EndPointName)
{
    return CreateEndpointAddress(ServiceURL, EndPointName, this.userPrincipleName);
}
/// <summary>
/// Create and endpoint address based on service URL, endpointname and principalname.
/// </summary>
/// <param name="ServiceURL">Path to the server services root.</param>
/// <param name="EndPointName">Name of the service endpoint</param>
/// <param name="UserPrincipalName">UPN/SPN for endpoint delegation</param>
/// <returns>EndpointAddress</returns>
private EndpointAddress CreateEndpointAddress(string ServiceURL, string EndPointName, string UserPrincipalName)
{
    EndpointAddress endpointAddress;
    String EndpointURIPath;
	char[] split = new char[] {'/'};
	
    // determine service endpoint address
    switch (EndPointName.ToLower())
    {
        case "resource":
            EndpointURIPath = Constants.Endpoint.Resource.Split(split, 2)[1];
            break;
        case "resourcefactory":
            EndpointURIPath = Constants.Endpoint.ResourceFactory.Split(split, 2)[1];
            break;
        case "enumeration":
            EndpointURIPath = Constants.Endpoint.Enumeration.Split(split, 2)[1];
            break;
        case "alternate":
            EndpointURIPath = Constants.Endpoint.Alternate.Split(split, 2)[1];
            break;
        case "mex":
            EndpointURIPath = Constants.Endpoint.MEX.Split(split, 2)[1];
            break;
        default:
            EndpointURIPath = EndPointName;
            break;
    }

    if (!string.IsNullOrEmpty(UserPrincipalName))
    {
        // Determine the method to call for the Endpoint Identity.
        if (UserPrincipalName.Contains("/") && !UserPrincipalName.Contains("@"))
        {
            // Create the SPN
            endpointAddress = new EndpointAddress(new Uri(ServiceURL + EndpointURIPath), EndpointIdentity.CreateSpnIdentity(UserPrincipalName));
        }
        else
        {
            // Create the UPN
            endpointAddress = new EndpointAddress(new Uri(ServiceURL + EndpointURIPath), EndpointIdentity.CreateUpnIdentity(UserPrincipalName));
        }
    }
    else
    {
        endpointAddress = new EndpointAddress(ServiceURL + EndpointURIPath);
    }
    return endpointAddress;
}

 

 

// Variables to hold the input Service URL and User Principle Name
private String serviceURL = "";
private String userPrincipleName = "";

// Constructor using Programmatic Bindings and DefaultNetworkCredentials
public DefaultClient(
    string serviceURL,
    string userPrincipleName)
    : this(
        CredentialCache.DefaultNetworkCredentials,
        serviceURL,
        userPrincipleName)
{
}

// Constructor using Programmatic Bindings with specified NetworkCredentials
public DefaultClient(
    NetworkCredential clientCredential,
    string serviceURL,
    string userPrincipleName)
{
    // Set the service URL and Principle Name
    this.userPrincipleName = userPrincipleName;

    // Make sure there is a trailing slash "/"
    if (serviceURL.EndsWith("/"))
        this.serviceURL = serviceURL;
    else
        this.serviceURL = serviceURL + "/";

    // Create the Objects we need for this client
    this.wsTransferClient = new WsTransferClient(CreateWSHttpContextBinding("ServiceMultipleTokenBinding_Resource"),
                                                 CreateEndpointAddress(this.serviceURL, "Resource", this.userPrincipleName));
    this.wsTransferFactoryClient = new WsTransferFactoryClient(CreateWSHttpContextBinding("ServiceMultipleTokenBinding_ResourceFactory"),
                                                               CreateEndpointAddress(this.serviceURL, "ResourceFactory", this.userPrincipleName));
    this.wsEnumerationClient = new WsEnumerationClient(CreateWSHttpContextBinding("ServiceMultipleTokenBinding_Enumeration"),
                                                       CreateEndpointAddress(this.serviceURL, "Enumeration", this.userPrincipleName));
    this.mexClient = new MexClient(CreateWSHttpBinding("MetadataExchangeHttpBinding_IMetadataExchange"),
                                   CreateEndpointAddress("MEX"));

    this.resourceFactory = new RmResourceFactory();
    this.requestFactory = new RmRequestFactory();
   
    this.ClientCredential = clientCredential;
}

/// <summary>
/// Create a new WSHttpBinding
/// </summary>
/// <param name="ContextName">name of binding</param>
/// <returns>WSHttpBinding</returns>
private static WSHttpBinding CreateWSHttpBinding(string ContextName)
{
    // ToDo: Refactor as a new class. Replace hard-coded values with public properties.
    WSHttpBinding oMetadataExchangeHttpBinding = new WSHttpBinding();
    oMetadataExchangeHttpBinding.Name = ContextName;
    oMetadataExchangeHttpBinding.CloseTimeout = new TimeSpan(0, 1, 0);
    oMetadataExchangeHttpBinding.OpenTimeout = new TimeSpan(0, 1, 0);
    oMetadataExchangeHttpBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
    oMetadataExchangeHttpBinding.SendTimeout = new TimeSpan(0, 1, 0);
    oMetadataExchangeHttpBinding.BypassProxyOnLocal = false;
    oMetadataExchangeHttpBinding.TransactionFlow = false;
    oMetadataExchangeHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
    oMetadataExchangeHttpBinding.MaxBufferPoolSize = 524288;
    oMetadataExchangeHttpBinding.MaxReceivedMessageSize = 965536;
    oMetadataExchangeHttpBinding.MessageEncoding = WSMessageEncoding.Text;
    oMetadataExchangeHttpBinding.TextEncoding = Encoding.UTF8;
    oMetadataExchangeHttpBinding.UseDefaultWebProxy = true;
    oMetadataExchangeHttpBinding.AllowCookies = false;
    oMetadataExchangeHttpBinding.ReaderQuotas = new XmlDictionaryReaderQuotas();
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxDepth = 32;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxStringContentLength = 8192;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxArrayLength = 16384;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
    oMetadataExchangeHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
    oMetadataExchangeHttpBinding.ReliableSession.Ordered = true;
    oMetadataExchangeHttpBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
    oMetadataExchangeHttpBinding.ReliableSession.Enabled = false;
    oMetadataExchangeHttpBinding.Security.Mode = SecurityMode.None;
    oMetadataExchangeHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    oMetadataExchangeHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
    oMetadataExchangeHttpBinding.Security.Transport.Realm = "";
    oMetadataExchangeHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    oMetadataExchangeHttpBinding.Security.Message.NegotiateServiceCredential = true;
    oMetadataExchangeHttpBinding.Security.Message.EstablishSecurityContext = true;
    return oMetadataExchangeHttpBinding;
}

/// <summary>
/// Create a new WSHttpContextBinding
/// </summary>
/// <param name="ContextName">name of binding</param>
/// <returns>WSHttpContextBinding</returns>
private static WSHttpContextBinding CreateWSHttpContextBinding(string ContextName)
{
    // ToDo: Refactor as a new class. Replace hard-coded values with public properties.
    WSHttpContextBinding oContextBinding = new WSHttpContextBinding();
    oContextBinding.Name = ContextName;
    oContextBinding.CloseTimeout = new TimeSpan(0, 1, 0);
    oContextBinding.OpenTimeout = new TimeSpan(0, 1, 0);
    oContextBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
    oContextBinding.SendTimeout = new TimeSpan(0, 1, 0);
    oContextBinding.BypassProxyOnLocal = false;
    oContextBinding.TransactionFlow = false;
    oContextBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
    oContextBinding.MaxBufferPoolSize = 524288;
    oContextBinding.MaxReceivedMessageSize = 2621440;  // This needs to be configurable!!!
    oContextBinding.MessageEncoding = WSMessageEncoding.Text;
    oContextBinding.TextEncoding = Encoding.UTF8;
    oContextBinding.UseDefaultWebProxy = true;
    oContextBinding.AllowCookies = false;
    oContextBinding.ContextProtectionLevel = System.Net.Security.ProtectionLevel.Sign;
    oContextBinding.ReaderQuotas = new XmlDictionaryReaderQuotas();
    oContextBinding.ReaderQuotas.MaxDepth = 32;
    oContextBinding.ReaderQuotas.MaxStringContentLength = 8192;
    oContextBinding.ReaderQuotas.MaxArrayLength = 16384;
    oContextBinding.ReaderQuotas.MaxBytesPerRead = 4096;
    oContextBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
    oContextBinding.ReliableSession.Ordered = true;
    oContextBinding.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
    oContextBinding.ReliableSession.Enabled = false;
    oContextBinding.Security.Mode = SecurityMode.Message;
    oContextBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
    oContextBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
    oContextBinding.Security.Transport.Realm = "";
    oContextBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    oContextBinding.Security.Message.NegotiateServiceCredential = true;
    oContextBinding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
    oContextBinding.Security.Message.EstablishSecurityContext = false;
    return oContextBinding;
}

/// <summary>
/// Create and endpoint address based on endpointname.
/// </summary>
/// <param name="EndPointName">Name of the service endpoint</param>
/// <returns>EndpointAddress</returns>
private EndpointAddress CreateEndpointAddress(string EndPointName)
{
    return CreateEndpointAddress(this.serviceURL, EndPointName, this.userPrincipleName);
}
/// <summary>
/// Create and endpoint address based on service URL and endpointname.
/// </summary>
/// <param name="ServiceURL">Path to the server services root.</param>
/// <param name="EndPointName">Name of the service endpoint</param>
/// <returns>EndpointAddress</returns>
private EndpointAddress CreateEndpointAddress(string ServiceURL, string EndPointName)
{
    return CreateEndpointAddress(ServiceURL, EndPointName, this.userPrincipleName);
}
/// <summary>
/// Create and endpoint address based on service URL, endpointname and principalname.
/// </summary>
/// <param name="ServiceURL">Path to the server services root.</param>
/// <param name="EndPointName">Name of the service endpoint</param>
/// <param name="UserPrincipalName">UPN/SPN for endpoint delegation</param>
/// <returns>EndpointAddress</returns>
private EndpointAddress CreateEndpointAddress(string ServiceURL, string EndPointName, string UserPrincipalName)
{
    EndpointAddress endpointAddress;
    String EndpointURIPath;
    char[] split = new char[] {'/'};
   
    // determine service endpoint address
    switch (EndPointName.ToLower())
    {
        case "resource":
            EndpointURIPath = Constants.Endpoint.Resource.Split(split, 2)[1];
            break;
        case "resourcefactory":
            EndpointURIPath = Constants.Endpoint.ResourceFactory.Split(split, 2)[1];
            break;
        case "enumeration":
            EndpointURIPath = Constants.Endpoint.Enumeration.Split(split, 2)[1];
            break;
        case "alternate":
            EndpointURIPath = Constants.Endpoint.Alternate.Split(split, 2)[1];
            break;
        case "mex":
            EndpointURIPath = Constants.Endpoint.MEX.Split(split, 2)[1];
            break;
        default:
            EndpointURIPath = EndPointName;
            break;
    }

    if (!string.IsNullOrEmpty(UserPrincipalName))
    {
        // Determine the method to call for the Endpoint Identity.
        if (UserPrincipalName.Contains("/") && !UserPrincipalName.Contains("@"))
        {
            // Create the SPN
            endpointAddress = new EndpointAddress(new Uri(ServiceURL + EndpointURIPath), EndpointIdentity.CreateSpnIdentity(UserPrincipalName));
        }
        else
        {
            // Create the UPN
            endpointAddress = new EndpointAddress(new Uri(ServiceURL + EndpointURIPath), EndpointIdentity.CreateUpnIdentity(UserPrincipalName));
        }
    }
    else
    {
        endpointAddress = new EndpointAddress(ServiceURL + EndpointURIPath);
    }
    return endpointAddress;
}
Oct 31, 2013 at 9:32 PM
Edited Oct 31, 2013 at 9:33 PM
I believe the declaration of Alternate client is missing from one of the constructors above:

this.alternateClient = new AlternateClient(Utilities.CreateWSHttpContextBinding("ServiceMultipleTokenBinding_Alternate"), CreateEndpointAddress("Alternate"));

The code will break without this line when trying to assign credentials to each of the clients.

Ilya

P.S. Many thanks to the author of the above code! Helped tremendously.
Oct 31, 2013 at 10:19 PM
@Rockmus

Yes, I believe you are correct.
The code would break when attempting a password reset or registration for password reset for sure. I don't know of any other methods that use the alternate endpoint.
Thank you for pointing out this bug and for working through it to provide a resolution to the community!
Nov 1, 2013 at 3:08 PM
I should point out that Utilities is the namespace I put those functions under. They do not go there by default. If you end up putting everything in DefaultClient.cs, you don't need a namespace.

Actually, the way the credentials property is set up, it assigns credentials to all 5 clients regardless (on this.ClientCredential = ... call in the constructor):

Property Set method looks like this:

this.wsTransferClient.ClientCredentials.Windows.ClientCredential = value;
this.wsTransferFactoryClient.ClientCredentials.Windows.ClientCredential = value;
this.wsEnumerationClient.ClientCredentials.Windows.ClientCredential = value;
this.mexClient.ClientCredentials.Windows.ClientCredential = value;
this.alternateClient.ClientCredentials.Windows.ClientCredential = value;

So all 5 clients have to be initialized or a null check introduced in the ClientCredential property.

Ilya
May 7, 2014 at 11:14 AM
Thanks for this! Just what I am looking for. Basically in my .Net application, I need to call 2 FIM Services, so having this dynamic client is awesome.
Can you also put the necessary "using" statements? I tried to add these codes to the DefaultClient class but its showing some reference issues.
Thanks a lot and more power!

Joseph
May 7, 2014 at 12:00 PM
Now it works for me. I instantiate the DefaultClient like this:
using (DefaultClient client = new DefaultClient("http://my.domain.com:5725/ResourceManagementService/", "srv_acount@my.domain.com")) { } Btw, for the references, these are the imports that is in my DefaultClient class (hoping to help someone also):
using System;
using System.Net;
using System.Text;
using System.Xml;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Schema;
using Microsoft.ResourceManagement.Client.WsEnumeration;
using System.ServiceModel;
using Microsoft.ResourceManagement.Client;
using Microsoft.ResourceManagement.Client.WsTransfer;
using Microsoft.ResourceManagement.ObjectModel;
using Microsoft.ResourceManagement.ObjectModel.ResourceTypes;
using System.ServiceModel.Channels;
using Microsoft.ResourceManagement.Client.WsTrust;
using System.IdentityModel.Tokens;
using System.Runtime.Serialization;
using System.Threading;
using Microsoft.ResourceManagement.WebServices.Client;
using Microsoft.ResourceManagement.Client.Faults;


Really big thanks mgercevich!!!