Configuring a WCF service in a class library has been something that has been a struggle for me in the past. There was always something that I knew should be done differently, as it just didn’t “feel” right to have to recompile the class library when we move from a test environment to a production environment.
This specific example uses WCF to connect to Authorize.NET’s ARB service for creating subscriptions.
Here is what I came up with:
// Be sure to configure this in the database for the various environments, as needed EndpointAddress ea = new EndpointAddress(YourDataAccess.GetUrl); // HTTPS BasicHttpBinding serviceBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); serviceBinding.ReceiveTimeout = new TimeSpan(0,0,0,20); ARB.ServiceSoapClient service = new ARB.ServiceSoapClient(serviceBinding, ea); ARB.ARBCreateSubscriptionResponseType response; // Set the credentials authentication = new ARB.MerchantAuthenticationType(); authentication.name = this.AuthNetName(); authentication.transactionKey = this.AuthNetTxn(); response = service.ARBCreateSubscription(authentication, sub);