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);
            }
        }
Exemplo n.º 2
0
        private void FillTreeView()
        {
            tvwServices.BeginUpdate();

            tvwServices.Nodes.Clear();

            for (int i = 0; i < ServiceInfos.Count; i++)
            {
                ServiceInfo serviceInfo = ServiceInfos[i];
                TreeNode    serviceNode = new TreeNode(serviceInfo.Wsdl);

                List <ContractInfo> contractInfos = serviceInfo.Contracts;
                for (int j = 0; j < contractInfos.Count; j++)
                {
                    ContractInfo contractInfo = contractInfos[j];
                    TreeNode     contractNode = new TreeNode(contractInfo.ContractName);

                    List <OperationInfo> operationInfos = contractInfo.Operations;
                    for (int k = 0; k < operationInfos.Count; k++)
                    {
                        OperationInfo operationInfo = operationInfos[k];
                        TreeNode      operationNode = new TreeNode(operationInfo.Method.Name);
                        operationNode.Tag = operationInfo;
                        contractNode.Nodes.Add(operationNode);
                    }

                    serviceNode.Nodes.Add(contractNode);
                }

                TreeNode configNode = new TreeNode("Config");
                configNode.Name        = "ConfigNode";
                configNode.Tag         = serviceInfo.Config;
                configNode.ToolTipText = serviceInfo.Wsdl + " Config";
                serviceNode.Nodes.Add(configNode);

                tvwServices.Nodes.Add(serviceNode);
            }

            tvwServices.ExpandAll();
            tvwServices.EndUpdate();
        }
        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);
            }
        }