private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                ServiceClientProxyFactoryGenerator proxyFactoryGenerator = new ServiceClientProxyFactoryGenerator(new ServiceMetadataDownloader(), new ServiceMetadataImporter(new CSharpCodeDomProviderFactory()), new ServiceClientProxyCompiler());
                ServiceClientProxyFactory          proxyFactory          = proxyFactoryGenerator.GenerateProxyFactory(Wsdl);
                List <ServiceInfo> serviceInfos = new List <ServiceInfo>();
                ServiceInfo        serviceInfo  = new ServiceInfo {
                    Wsdl = Wsdl, Config = proxyFactory.Config
                };
                for (int index = 0; index < proxyFactory.Contracts.Count; index++)
                {
                    ContractDescription contractDescription = proxyFactory.Contracts[index];
                    string             contractName         = contractDescription.Name;
                    ServiceClientProxy proxy          = proxyFactory.CreateProxy(contractName, contractDescription.Namespace);
                    string[]           operationNames = contractDescription.Operations.Select(x => x.Name).ToArray();
                    ContractInfo       contractInfo   = new ContractInfo {
                        Proxy = proxy, ContractName = contractName
                    };

                    for (int i = 0; i < operationNames.Length; i++)
                    {
                        string operationName = operationNames[i];
                        object instance      = proxy.CreateInstance();
                        using (instance as IDisposable)
                        {
                            Method method = ReflectionUtils.GetMethodDefinition(instance, operationName);
                            contractInfo.Operations.Add(new OperationInfo {
                                Contract = contractInfo, Method = method
                            });
                        }
                    }
                    serviceInfo.Contracts.Add(contractInfo);
                }
                serviceInfos.Add(serviceInfo);

                m_Services = serviceInfos.AsReadOnly();
            }
            catch (Exception exception)
            {
                ShowErrorForm.ShowDialog(this, exception);
            }
        }
Esempio n. 2
0
        private ServiceInfo GetServiceInfo(string wsdl)
        {
            var proxyFactoryGenerator = new ServiceClientProxyFactoryGenerator(
                new ServiceMetadataDownloader(),
                new ServiceMetadataImporter(
                    new CSharpCodeDomProviderFactory()),
                new ServiceClientProxyCompiler());
            var proxyFactory = proxyFactoryGenerator.GenerateProxyFactory(wsdl);
            var serviceInfo  = new ServiceInfo {
                Wsdl = wsdl, Config = proxyFactory.Config
            };
            var serviceEndpoints = proxyFactory.Endpoints;

            foreach (var serviceEndpoint in serviceEndpoints)
            {
                var contractDescription = serviceEndpoint.Contract;
                var contractName        = contractDescription.Name;

                var proxy = proxyFactory.CreateProxy(serviceEndpoint);

                var operationNames = contractDescription.Operations.Select(x => x.Name).ToArray();
                var contractInfo   = new ContractInfo {
                    Proxy = proxy, ContractName = contractName
                };
                var endPointInfo = new EndPointInfo {
                    BindingName = serviceEndpoint.Binding.Name, ContractInfo = contractInfo
                };

                foreach (var operationName in operationNames)
                {
                    var instance = proxy.CreateInstance();
                    using (instance as IDisposable)
                    {
                        var method = ReflectionUtils.GetMethodDefinition(instance, operationName);
                        contractInfo.Operations.Add(new OperationInfo {
                            Contract = contractInfo, Method = method
                        });
                    }
                }
                serviceInfo.EndPoints.Add(endPointInfo);
            }
            return(serviceInfo);
        }