本文整理匯總了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();
//.........這裏部分代碼省略.........