当前位置: 首页>>代码示例>>C#>>正文


C# ChannelFactory.SomeOperation方法代码示例

本文整理汇总了C#中System.ServiceModel.ChannelFactory.SomeOperation方法的典型用法代码示例。如果您正苦于以下问题:C# ChannelFactory.SomeOperation方法的具体用法?C# ChannelFactory.SomeOperation怎么用?C# ChannelFactory.SomeOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.ChannelFactory的用法示例。


在下文中一共展示了ChannelFactory.SomeOperation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Console.WriteLine(".......\nWCF NET.TCP Scan\n");
            if (args.Count() < 1)
            {
                Console.WriteLine("ERROR: Missing endpoint URL");
                DisplayUsage();
                return;
            }
            var uri = new Uri(args[0]);
            Console.WriteLine(uri);
            string userid = "";
            string password = "";
            try
            {
                userid = args[1];
                password = args[2];
            }
            catch { }
            string currentUser = "";
            try
            {
                currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            }
            catch
            {
                currentUser = "unknown";
            }
            if (!IsValidEndpoint(uri))
            {
                DisplayUsage();
                return;
            }
            Console.WriteLine(" + Testing with generic contract as {0}", currentUser);

            foreach (var mode in Enum.GetValues(typeof(SecurityMode)).Cast<SecurityMode>())
            {
                try
                {
                    var address = new EndpointAddress(uri);
                    var binding = new NetTcpBinding(mode);
                    var service = new ChannelFactory<IDataAccess>(binding, address).CreateChannel();
                    var result = service.SomeOperation("blah");
                }
                catch (ActionNotSupportedException)
                {
                    //Contract mismatch, i.e. the binding config is ok, but wrong contract is specified, which is what we expect...
                    Console.WriteLine(" + Server accepted \"{0}\" security mode", mode);
                    if (mode == SecurityMode.None)
                    {
                        Console.WriteLine("***WARNING*** No authentication or transport encryption enabled on binding!");
                    }
                    if (mode == SecurityMode.Transport)
                    {
                        try
                        {
                            //resend without creds to verify server is authenticating:
                            var address = new EndpointAddress(uri);
                            var binding = new NetTcpBinding(mode);
                            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                            var factory = new ChannelFactory<IDataAccess>(binding, address);
                            var service = factory.CreateChannel();
                            var result = service.SomeOperation("blah");
                        }
                        catch (ActionNotSupportedException anse)
                        {
                            Console.WriteLine("***WARNING**** Server does not require authentication!", mode);
                            Console.WriteLine(anse.InnerException.Message);
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("   * Server required credentials: {0}", currentUser);
                        }
                    }
                }
                catch (ProtocolException)
                {
                    Console.WriteLine(" - Server rejected \"{0}\" mode", mode);
                }
                catch (SecurityNegotiationException sne)
                {
                    if (sne.InnerException.InnerException != null &&
                        sne.InnerException.InnerException.Message.ToLower().Contains("target principal"))
                    {
                        Console.WriteLine(" + \"{0}\" security mode accepted, but rejected {1}: {2}", mode, currentUser, sne.InnerException.InnerException.Message);
                        try
                        {
                            if (mode == SecurityMode.Transport
                                && !string.IsNullOrWhiteSpace(userid)
                                && !string.IsNullOrWhiteSpace(password))
                            {
                                //try it again with specified creds
                                var address = new EndpointAddress(uri);
                                var binding = new NetTcpBinding(mode);
                                binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                                var factory = new ChannelFactory<IDataAccess>(binding, address);
                                Console.WriteLine("   * Retrying specified credentials {0}:{1}", userid, password);
                                factory.Credentials.UserName.UserName = userid;
                                factory.Credentials.UserName.UserName = password;
                                var service = factory.CreateChannel();
//.........这里部分代码省略.........
开发者ID:Rackme,项目名称:WcfScan,代码行数:101,代码来源:Program.cs


注:本文中的System.ServiceModel.ChannelFactory.SomeOperation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。