/// <summary>
        ///
        /// </summary>
        /// <param name="accountCredentials"></param>
        /// <returns>A disposable object you should wrap in using() statement</returns>
        public static DocuSignWeb.APIServiceSoap CreateApiProxy(AccountCredentials accountCredentials)
        {
#if true
            // the envelope is finally constructed we are ready to send it in
            DocuSignWeb.APIServiceSoapClient apiService = new DocuSignWeb.APIServiceSoapClient("APIServiceSoap", accountCredentials.ApiUrl);

            apiService.ClientCredentials.UserName.UserName = accountCredentials.UserName;
            apiService.ClientCredentials.UserName.Password = accountCredentials.Password;

            return(apiService);
#else       // this is a security token configuration
            // this is required for certain calls like RequestRecipientToken
            // you need to get a certificate from Thawte or VeriSign first and install it
            DocuSignWeb.APIServiceSoapClient apiService = new DocuSignWeb.APIServiceSoapClient("APIServiceSoap1", accountCredentials.ApiUrl);
            apiService.ClientCredentials.UserName.UserName = "******" + ConfigurationManager.AppSettings["IntegratorsKey"] + "]" + ConfigurationManager.AppSettings["APIUserEmail"];
            apiService.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["Password"];

            //
            // need to add the supporting token since DocuSign uses dual authentication for
            // for critical calls
            CustomBinding                   binding         = (CustomBinding)apiService.Endpoint.Binding;
            BindingElementCollection        elements        = binding.CreateBindingElements();
            SecurityBindingElement          security        = elements.Find <SecurityBindingElement>();
            UserNameSecurityTokenParameters tokenParameters = new UserNameSecurityTokenParameters();
            tokenParameters.InclusionMode      = SecurityTokenInclusionMode.AlwaysToRecipient;
            tokenParameters.RequireDerivedKeys = false;
            security.EndpointSupportingTokenParameters.SignedEncrypted.Add(
                tokenParameters);
            apiService.Endpoint.Binding = new CustomBinding(elements.ToArray());;
            return(apiService);
#endif
        }
        public static APIServiceSoap CreateApiProxy(Account Identity, string password)
        {
#if true
            // the envelope is finally constructed we are ready to send it in
            AccountCredentials accountCredentials = new AccountCredentials();

            //If there are many accounts then the firet one is chosen for sending
            accountCredentials.AccountId = Identity.AccountID;
            accountCredentials.ApiUrl    = "https://demo.docusign.net/api/3.0/api.asmx";
            APIServiceSoapClient apiService = new APIServiceSoapClient("APIServiceSoap", accountCredentials.ApiUrl);
            apiService.ClientCredentials.UserName.UserName = Identity.UserID;
            apiService.ClientCredentials.UserName.Password = password;

            return(apiService);
#else       // this is a security token configuration
            // this is required for certain calls like RequestRecipientToken
            // you need to get a certificate from Thawte or VeriSign first and install it
            DocuSignWeb.APIServiceSoapClient apiService = new DocuSignWeb.APIServiceSoapClient("APIServiceSoap1", accountCredentials.ApiUrl);
            apiService.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["APIUserName"];
            apiService.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["Password"];

            //
            // need to add the supporting token since DocuSign uses dual authentication for
            // for critical calls
            CustomBinding                   binding         = (CustomBinding)apiService.Endpoint.Binding;
            BindingElementCollection        elements        = binding.CreateBindingElements();
            SecurityBindingElement          security        = elements.Find <SecurityBindingElement>();
            UserNameSecurityTokenParameters tokenParameters = new UserNameSecurityTokenParameters();
            tokenParameters.InclusionMode      = SecurityTokenInclusionMode.AlwaysToRecipient;
            tokenParameters.RequireDerivedKeys = false;
            security.EndpointSupportingTokenParameters.SignedEncrypted.Add(
                tokenParameters);
            apiService.Endpoint.Binding = new CustomBinding(elements.ToArray());;
            return(apiService);
#endif
        }
Esempio n. 3
0
        static void Main()
        {
            // use Steeltoe to parse VCAP_APPLICATION env variables into config object
            var builder    = new ConfigurationBuilder().AddCloudFoundry();
            var config     = builder.Build();
            var opts       = new CloudFoundryApplicationOptions();
            var appSection = config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX);

            appSection.Bind(opts);

            // get external TCP route (format: ["fullyqualifieddomainname.com:80000"])
            var appRouteHostAndExternalPort = opts.ApplicationUris.FirstOrDefault().Split(':');
            var appRouteHost    = appRouteHostAndExternalPort.ElementAtOrDefault(0);
            var appExternalPort = appRouteHostAndExternalPort.ElementAtOrDefault(1);

            if (appRouteHost == "" || appExternalPort == "")
            {
                throw new System.ArgumentException("Invalid VCAP_APPLICATION route or port");
            }

            // ensure external TCP port and internal listening $PORT are the same
            var appInternalPort = opts.Port.ToString();

            if (appInternalPort != appExternalPort)
            {
                throw new System.ArgumentException($"Internal listening port must match External Route port : {appInternalPort} != {appExternalPort}");
            }
            Console.WriteLine($"URI: {appRouteHost}:{appInternalPort}");


            // have endpoints listen on public URI
            var baseAddress = new Uri($"net.tcp://{appRouteHost}:{appInternalPort}/example/service");
            var svcHost     = new ServiceHost(typeof(HelloWorld), baseAddress);

            // enable verbose errors
            ServiceDebugBehavior debug = svcHost.Description.Behaviors.Find <ServiceDebugBehavior>();

            debug.IncludeExceptionDetailInFaults = true;

            var netTcpBinding = new NetTcpBinding();

            netTcpBinding.Security.Mode = SecurityMode.None;

            // use custom binding to reduce connection pool settings to work better in load-balanced scenario (https://stackoverflow.com/questions/9714426/disable-connection-pooling-for-wcf-net-tcp-bindings)
            BindingElementCollection   bindingElementCollection = netTcpBinding.CreateBindingElements();
            TcpTransportBindingElement transport = bindingElementCollection.Find <TcpTransportBindingElement>();

            transport.ConnectionPoolSettings.IdleTimeout  = TimeSpan.Zero;
            transport.ConnectionPoolSettings.LeaseTimeout = TimeSpan.Zero;
            transport.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 0;

            CustomBinding balancedTcpBinding = new CustomBinding();

            balancedTcpBinding.Elements.AddRange(bindingElementCollection.ToArray());
            balancedTcpBinding.Name = "NetTcpBinding";


            // add metadata endpoint
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

            svcHost.Description.Behaviors.Add(smb);

            svcHost.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                balancedTcpBinding,
                "mex"
                );

            // add service endpoint
            svcHost.AddServiceEndpoint(
                typeof(IHelloWorld),
                balancedTcpBinding,
                "IHelloWorld"
                );

            svcHost.Open();
            Console.WriteLine($"svcHost is {svcHost.State}.  Press enter to close.");

            Thread.Sleep(Timeout.Infinite);
            svcHost.Close();
        }