Exemplo n.º 1
0
        /// <summary>
        /// Reads the headers from App.config.
        /// </summary>
        /// <param name="config">The configuration class.</param>
        protected override void ReadHeadersFromConfig(AppConfig config)
        {
            AdManagerAppConfig adManagerConfig = (AdManagerAppConfig)config;

            this.requestHeader                 = new RequestHeader();
            this.requestHeader.networkCode     = adManagerConfig.NetworkCode;
            this.requestHeader.applicationName = adManagerConfig.GetUserAgent();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a service object.
        /// </summary>
        /// <param name="signature">Signature of the service being created.</param>
        /// <param name="user">The user for which the service is being created.
        /// <param name="serverUrl">The server to which the API calls should be
        /// made.</param>
        /// </param>
        /// <returns>An object of the desired service type.</returns>
        public override AdsClient CreateService(ServiceSignature signature, AdsUser user,
                                                Uri serverUrl)
        {
            AdManagerAppConfig adManagerConfig = (AdManagerAppConfig)Config;

            if (serverUrl == null)
            {
                serverUrl = new Uri(adManagerConfig.AdManagerApiServer);
            }

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            CheckServicePreconditions(signature);

            AdManagerServiceSignature adManagerSignature = signature as AdManagerServiceSignature;
            EndpointAddress           endpoint           = new EndpointAddress(string.Format(ENDPOINT_TEMPLATE,
                                                                                             serverUrl, adManagerSignature.Version, adManagerSignature.ServiceName));

            // Create the binding for the service
            BasicHttpBinding binding = new BasicHttpBinding();

            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.TextEncoding           = Encoding.UTF8;

            AdsClient service = (AdsClient)Activator.CreateInstance(adManagerSignature.ServiceType,
                                                                    new object[]
            {
                binding,
                endpoint
            });

            ServiceEndpoint serviceEndpoint =
                (ServiceEndpoint)service.GetType().GetProperty("Endpoint").GetValue(service, null);

            AdsServiceInspectorBehavior inspectorBehavior = new AdsServiceInspectorBehavior();

            inspectorBehavior.Add(new OAuthClientMessageInspector(user.OAuthProvider));

            RequestHeader clonedHeader = (RequestHeader)requestHeader.Clone();

            clonedHeader.Version = adManagerSignature.Version;
            inspectorBehavior.Add(new AdManagerSoapHeaderInspector()
            {
                RequestHeader = clonedHeader,
                Config        = adManagerConfig
            });
            inspectorBehavior.Add(new SoapListenerInspector(user, adManagerSignature.ServiceName));
            inspectorBehavior.Add(new SoapFaultInspector <AdManagerApiException>()
            {
                ErrorType =
                    adManagerSignature.ServiceType.Assembly.GetType(
                        adManagerSignature.ServiceType.Namespace + ".ApiException"),
            });
#if NET452
            serviceEndpoint.Behaviors.Add(inspectorBehavior);
#else
            serviceEndpoint.EndpointBehaviors.Add(inspectorBehavior);
#endif

            if (adManagerConfig.Proxy != null)
            {
                service.Proxy = adManagerConfig.Proxy;
            }

            service.EnableDecompression = adManagerConfig.EnableGzipCompression;
            service.Timeout             = adManagerConfig.Timeout;
            service.UserAgent           = adManagerConfig.GetUserAgent();

            service.Signature = signature;
            service.User      = user;
            return(service);
        }
 /// <summary>
 /// Public constructor. Use this version if you want to construct
 /// a AdManagerUser with a custom configuration.
 /// </summary>
 public AdManagerUser(AdManagerAppConfig config) : base(config)
 {
 }