本文整理汇总了C#中System.ServiceModel.ChannelFactory.ConfigureChannelFactory方法的典型用法代码示例。如果您正苦于以下问题:C# ChannelFactory.ConfigureChannelFactory方法的具体用法?C# ChannelFactory.ConfigureChannelFactory怎么用?C# ChannelFactory.ConfigureChannelFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.ChannelFactory
的用法示例。
在下文中一共展示了ChannelFactory.ConfigureChannelFactory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoStuff
public ActionResult DoStuff()
{
var channelFactory = new ChannelFactory<Services.IEchoClaimsChannel>("WS2007FederationHttpBinding_IEchoClaims");
channelFactory.ConfigureChannelFactory();
channelFactory.Credentials.SupportInteractive = false;
var claimsPrincipal = Thread.CurrentPrincipal as IClaimsPrincipal;
var channel = channelFactory.CreateChannelActingAs(claimsPrincipal.Identities.First().BootstrapToken);
var success = false;
try
{
var result = channel.Echo();
if (channel.State != CommunicationState.Faulted)
{
channel.Close();
success = true;
}
return View(model: result);
}
finally
{
if (!success)
{
channel.Abort();
}
}
}
示例2: TestGenevaWebserviceProvider_WithSSL
public void TestGenevaWebserviceProvider_WithSSL()
{
X509Certificate2 sslCertJavaWSP = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, JavaWSPSSLCertificate);
X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameClient);
// Uri uri = new Uri("http://localhost:6020/Echo");
Uri uri = new Uri("https://csky-pc/test/Service1.svc");
EndpointAddress address = new EndpointAddress(uri);
SecurityToken issuedToken = TestJavaSTSConnection.GetIssuedToken();
using (ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(true), address))
{
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
factory.ConfigureChannelFactory();
factory.Credentials.ClientCertificate.Certificate = certificate2Client;
factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, "CN=STS");// SigningCertificateNameGenevaService);
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);
Structure str = new Structure();
str.value = "Badabam";
var echoRequest = new echo();
echoRequest.Framework = new LibertyFrameworkHeader();
echoRequest.structureToEcho = str;
var result = service.Echo(echoRequest);
Assert.AreEqual("Badabam", result.structureToEcho.value);
}
}
示例3: IsConfiguredAsFederated_ConfiguredIsCalled_ReturnsTrue
public void IsConfiguredAsFederated_ConfiguredIsCalled_ReturnsTrue()
{
// Arrange
var channelFactory = new ChannelFactory<IService>(new BasicHttpBinding(), new EndpointAddress("http://localhost"));
channelFactory.ConfigureChannelFactory();
// Act
var actual = channelFactory.IsConfiguredAsFederated();
// Assert
Assert.AreEqual(true, actual);
}
示例4: CreateProxy
private static IService CreateProxy()
{
// request identity token from ADFS
SecurityToken token = RequestIdentityToken();
// set up factory and channel
var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.EstablishSecurityContext = false;
var factory = new ChannelFactory<IService>(binding, _serviceEndpoint);
factory.Credentials.SupportInteractive = false;
// enable WIF on channel factory
factory.ConfigureChannelFactory();
return factory.CreateChannelWithIssuedToken(token);
}
示例5: ExecuteWS
public static string ExecuteWS(string signingCertificateNameClient, string address, SecurityToken issuedToken)
{
X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, signingCertificateNameClient);
ChannelFactory<IEchoService> factory = null;
try
{
factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(false), address);
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
factory.ConfigureChannelFactory();
factory.Credentials.ClientCertificate.Certificate = certificate2Client;
factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, "CN=STS");// SigningCertificateNameGenevaService);
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);
Structure str = new Structure();
str.value = "Testing .NET client";
var echoRequest = new echo();
echoRequest.Framework = new LibertyFrameworkHeader();
echoRequest.structureToEcho = str;
echoResponse result = null;
result = service.Echo(echoRequest);
return result.structureToEcho.value;
}
catch (Exception e)
{
if (factory != null && factory.State == CommunicationState.Opened)
{
factory.Close();
}
throw;
}
finally
{
if (factory.State == CommunicationState.Opened)
{
factory.Close();
}
}
}
示例6: _btnCallService_Click
private void _btnCallService_Click(object sender, RoutedEventArgs e)
{
var binding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;
var ep = new EndpointAddress("https://" + Constants.WebHost + "/webservicesecurity/soap.svc/bearer");
var factory = new ChannelFactory<IService>(binding, ep);
factory.Credentials.SupportInteractive = false;
factory.ConfigureChannelFactory();
var channel = factory.CreateChannelWithIssuedToken(RSTR.SecurityToken);
var claims = channel.GetClientIdentity();
var sb = new StringBuilder(128);
claims.ForEach(c => sb.AppendFormat("{0}\n {1}\n\n", c.ClaimType, c.Value));
_txtDebug.Text = sb.ToString();
}
示例7: CallMessage
private static void CallMessage(SamlSecurityToken token)
{
var factory = new ChannelFactory<IServiceClientChannel>(
new ClientSamlHttpBinding(SecurityMode.Message),
new EndpointAddress(
new Uri("http://roadie:9000/Services/ClientSaml/Message"),
EndpointIdentity.CreateDnsIdentity("Service")));
factory.Credentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.CurrentUser,
StoreName.My,
X509FindType.FindBySubjectDistinguishedName,
"CN=Service");
factory.ConfigureChannelFactory<IServiceClientChannel>();
var proxy = factory.CreateChannelWithIssuedToken<IServiceClientChannel>(token);
proxy.Ping("foo");
proxy.Close();
}
示例8: CallMixedMode
private static void CallMixedMode(SamlSecurityToken token)
{
var factory = new ChannelFactory<IServiceClientChannel>("*");
factory.ConfigureChannelFactory<IServiceClientChannel>();
var proxy = factory.CreateChannelWithIssuedToken<IServiceClientChannel>(token);
proxy.Ping("foo");
proxy.Close();
}
示例9: TestJavaWebserviceProviderWithSSL
public void TestJavaWebserviceProviderWithSSL()
{
X509Certificate2 sslCertJavaWSP = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, JavaWSPSSLCertificate);
X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameClient);
Uri uri = new Uri("https://172.16.232.1:8181/poc-provider/ProviderService");
EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity(sslCertJavaWSP);
EndpointAddress address = new EndpointAddress(uri, identity);
SecurityToken issuedToken = TestJavaSTSConnection.GetIssuedToken(new Uri("https://172.16.232.1:8181/poc-provider/ProviderService"));
ServicePointManager.ServerCertificateValidationCallback = delegate
{
return (true);
};//Removes Validationcheck of SSL certificate, should not be here for Production.
using (ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(true), address))
{
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
factory.ConfigureChannelFactory();
factory.Credentials.ClientCertificate.Certificate = certificate2Client;
factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameJavaService);
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);
Structure str = new Structure();
str.value = "Badabam";
var echoRequest = new echo();
echoRequest.Framework = new LibertyFrameworkHeader();
echoRequest.structureToEcho = str;
var result = service.Echo(echoRequest);
Assert.AreEqual("Badabam", result.structureToEcho.value);
}
}
示例10: WrongProfileForLibertyHeader
public void WrongProfileForLibertyHeader()
{
X509Certificate2 certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameClient);
Uri uri = new Uri("http://csky-pc/test/Service1.svc");
EndpointAddress address = new EndpointAddress(uri);
SecurityToken issuedToken = TestJavaSTSConnection.GetIssuedToken();
using (ChannelFactory<IEchoService> factory = new ChannelFactory<IEchoService>(new ServiceproviderBinding(false), address))
{
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
factory.ConfigureChannelFactory();
factory.Credentials.ClientCertificate.Certificate = certificate2Client;
factory.Credentials.ServiceCertificate.DefaultCertificate = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameGenevaService);
factory.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign;
var service = ChannelFactoryOperations.CreateChannelWithIssuedToken<IEchoService>(factory, issuedToken);
Structure str = new Structure();
str.value = "Badabam";
var echoRequest = new echo();
echoRequest.Framework = new LibertyFrameworkHeader();
echoRequest.Framework.Profile = "FailurToComply";
echoRequest.structureToEcho = str;
var result = service.Echo(echoRequest);
}
}