public static DynamicProxyLoader Load(String fileName, String @namespace, DynamicProxyLoaderOptions options) { @namespace = (@namespace ?? "Hmis_Service_Ref"); options = (options ?? new DynamicProxyLoaderOptions()); var dynamicProxyFactory = ReadCache(fileName); if (dynamicProxyFactory != null) { return(dynamicProxyFactory); } var proxyClientFileName = String.Format("{0}.config", fileName); var proxyAssemblyFileName = String.Format("{0}.dll", fileName); var proxyCodeFileName = String.Format("{0}.cs", fileName); var discoveryClient = new DiscoveryClientProtocol(); discoveryClient.ReadAll(proxyClientFileName); var proxyAssemblyBytes = File.ReadAllBytes(proxyAssemblyFileName); var proxyAssemblyCode = File.ReadAllText(proxyCodeFileName); var proxyAssembly = Assembly.Load(proxyAssemblyBytes); dynamicProxyFactory = new DynamicProxyLoader(discoveryClient, proxyAssembly, proxyAssemblyBytes, proxyAssemblyCode, @namespace, options); WriteCache(fileName, dynamicProxyFactory); return(dynamicProxyFactory); }
public static DynamicProxyLoader Load(Uri uri, String @namespace, DynamicProxyLoaderOptions options) { @namespace = (@namespace ?? $"DynamicService_{GetHandlerName(uri)}"); options = (options ?? new DynamicProxyLoaderOptions()); var discoveryClient = new DiscoveryClientProtocol { AllowAutoRedirect = true }; if (options.UseCredential) { var credentialCache = new CredentialCache(); var networkCredential = new NetworkCredential(options.UserName, options.Password, options.Domain); var uriPrefix = new Uri(uri.AbsoluteUri.Substring(0, uri.AbsoluteUri.Length - uri.AbsolutePath.Length)); var registeredModules = AuthenticationManager.RegisteredModules; while (registeredModules.MoveNext()) { credentialCache.Add(uriPrefix, ((IAuthenticationModule)registeredModules.Current).AuthenticationType, networkCredential); } discoveryClient.Credentials = credentialCache; } else { discoveryClient.Credentials = CredentialCache.DefaultCredentials; } discoveryClient.DiscoverAny(uri.ToString()); discoveryClient.ResolveAll(); return(new DynamicProxyLoader(discoveryClient, @namespace, options)); }
public DynamicProxyLoader(DiscoveryClientProtocol discoveryClient, Assembly assembly, byte[] assemblyBytes, String assemblyCode, String @namespace, DynamicProxyLoaderOptions options) { if (options == null) { throw new ArgumentNullException("options"); } Options = options; if (!String.IsNullOrEmpty(@namespace)) { if (!options.Namespaces.ContainsKey("*")) { options.Namespaces.Add("*", @namespace); } else { options.Namespaces["*"] = @namespace; } } DiscoveryClient = discoveryClient; AssemblyBytes = assemblyBytes; AssemblyCode = assemblyCode; Assembly = assembly; codeDomProvider = CodeDomProvider.CreateProvider(options.Language.ToString()); codeCompileUnit = new CodeCompileUnit(); contractGenerator = new ServiceContractGenerator(codeCompileUnit); contractGenerator.Options |= ServiceContractGenerationOptions.ClientClass; webReferenceOptions = new WebReferenceOptions(); DownloadMetadata(); ImportMetadata(); CreateProxy(); if (String.IsNullOrEmpty(assemblyCode)) { GenerateProxyCode(); } if (assembly == null && assemblyBytes != null) { Assembly = Assembly.Load(assemblyBytes); } else if (assembly != null && assemblyBytes == null) { AssemblyBytes = File.ReadAllBytes(Assembly.Location); } else if (Assembly == null && assemblyBytes == null) { CompileProxyCode(); } ServiceContracts = new List <Type>(); foreach (var contractDescription in ContractDescriptions) { var serviceContract = Assembly.GetType(contractDescription.Name); if (serviceContract != null) { ServiceContracts.Add(serviceContract); if (serviceContract.Name == ContractDescription.Name) { ServiceContract = serviceContract; } } } }
public DynamicProxyLoader(DiscoveryClientProtocol discoveryClient, String @namespace, DynamicProxyLoaderOptions options) : this(discoveryClient, null, null, null, @namespace, options) { }