예제 #1
0
        /// <summary>
        /// This method creates the proxy object and set the URL and Credentials properties.
        /// </summary>
        /// <param name="request">Request to be dispatched.</param>
        /// <param name="networkName">Current network name.</param>
        /// <returns>The proxy object which has been created.</returns>
        public virtual object GetOnlineProxy(Request request, string networkName)
        {
            Guard.ArgumentNotNull(request, "request");
            SoapHttpClientProtocol proxy = (SoapHttpClientProtocol)Activator.CreateInstance(request.OnlineProxyType);

            if ((catalog != null) && (catalog.Count > 0) && (catalog.EndpointExists(request.Endpoint)))
            {
                proxy.Credentials = catalog.GetCredentialForEndpoint(request.Endpoint, networkName);
                proxy.Url         = catalog.GetAddressForEndpoint(request.Endpoint, networkName);
            }

            return(proxy);
        }
예제 #2
0
        /// <summary>
        /// This method allows you to create the proxy object in concrete implementations.
        /// You can use the OnlineProxyType property of the Request to know the expected type for the proxy object.
        /// The concrete proxy factory should set specific properties in the proxy object like the URL and credentials.
        /// To set the URL, the proxy factory can use the network name and the Request's endpoint.
        /// </summary>
        /// <param name="request">Request to be dispatched.</param>
        /// <param name="networkName">Current network name.</param>
        /// <returns>The proxy object.</returns>
        public virtual object GetOnlineProxy(Request request, string networkName)
        {
            Guard.ArgumentNotNull(request, "request");

            ClientBase <TChannel> proxy = (ClientBase <TChannel>)Activator.CreateInstance(request.OnlineProxyType);

            // Set the credentials
            ClientCredentials clientCredentials = proxy.ClientCredentials;

            if ((endpointCatalog != null) && (endpointCatalog.Count > 0) && (endpointCatalog.EndpointExists(request.Endpoint)))
            {
                NetworkCredential networkCredential = EndpointCatalog.GetCredentialForEndpoint(request.Endpoint, networkName);

                clientCredentials.UserName.UserName = networkCredential.UserName;
                clientCredentials.UserName.Password = networkCredential.Password;
                EndpointAddress address = new EndpointAddress(EndpointCatalog.GetAddressForEndpoint(request.Endpoint, networkName));
                proxy.Endpoint.Address = address;
            }

            return(proxy);
        }