////// Class for creating and initializing WCF proxy clients. /// public class WCFClientFactory { ////// Gets an instance of WCF Proxy Class(Type "T"), and sets the credentials on it. /// ////// /// public static T CreateClient (CredentialType type) { object client = Activator.CreateInstance(typeof(T)); ClientCredentials clientCredentials = (ClientCredentials)client.GetType().GetProperty("ClientCredentials").GetValue(client, null); UserNamePasswordClientCredential credentials = clientCredentials.UserName; if (type == CredentialType.SAPBasic) { credentials.UserName = ConfigHelper.BackgroundUserName; credentials.Password = ConfigHelper.BackgroundUserPassword; } else if (type == CredentialType.MDM) { credentials.UserName = ConfigHelper.MDMUserName; credentials.Password = ConfigHelper.MDMPassword; } //Return initialized Proxy from Factory return (T)client; } //parameterless overload. public static T CreateClient () { return CreateClient (CredentialType.SAPBasic); }
You then call it like so:
Z_PO_CreateClient client = WCFClientFactory.CreateClient();
No comments:
Post a Comment