本文整理汇总了C#中System.ServiceModel.Channels.CustomBinding.BuildChannelFactory方法的典型用法代码示例。如果您正苦于以下问题:C# CustomBinding.BuildChannelFactory方法的具体用法?C# CustomBinding.BuildChannelFactory怎么用?C# CustomBinding.BuildChannelFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Channels.CustomBinding
的用法示例。
在下文中一共展示了CustomBinding.BuildChannelFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveFactory
public void ReceiveFactory()
{
Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisReceiveTransportBinding());
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>();
Assert.IsInstanceOf<RedisReceiveFactory>(factory);
}
示例2: Main
static void Main(string[] args)
{
try
{
BindingElement[] bindingElements = new BindingElement[2];
bindingElements[0] = new TextMessageEncodingBindingElement();
bindingElements[1] = new HttpTransportBindingElement();
CustomBinding binding = new CustomBinding(bindingElements);
using (Message message = Message.CreateMessage(binding.MessageVersion, "sendMessage", "Message Body"))
{
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
factory.Open();
IRequestChannel requestChannel = factory.CreateChannel(new EndpointAddress("http://localhost:9090/RequestReplyService"));
requestChannel.Open();
Message response = requestChannel.Request(message);
Console.WriteLine("Successful send message!");
Console.WriteLine("Receive a return message, action: {0}, body: {1}", response.Headers.Action, response.GetBody<String>());
requestChannel.Close();
factory.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally {
Console.Read();
}
}
示例3: ConnectAsync
public async Task<RelayConnection> ConnectAsync()
{
var tb = new TransportClientEndpointBehavior(tokenProvider);
var bindingElement = new TcpRelayTransportBindingElement(
RelayClientAuthenticationType.RelayAccessToken)
{
TransferMode = TransferMode.Buffered,
ConnectionMode = TcpRelayConnectionMode.Relayed,
ManualAddressing = true
};
bindingElement.GetType()
.GetProperty("TransportProtectionEnabled",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic)
.SetValue(bindingElement, true);
var rt = new CustomBinding(
new BinaryMessageEncodingBindingElement(),
bindingElement);
var cf = rt.BuildChannelFactory<IDuplexSessionChannel>(tb);
await Task.Factory.FromAsync(cf.BeginOpen, cf.EndOpen, null);
var ch = cf.CreateChannel(new EndpointAddress(address));
await Task.Factory.FromAsync(ch.BeginOpen, ch.EndOpen, null);
return new RelayConnection(ch)
{
WriteTimeout = (int) rt.SendTimeout.TotalMilliseconds,
ReadTimeout = (int) rt.ReceiveTimeout.TotalMilliseconds
};
}
示例4: BuildChannelWithoutProtectionTokenParameters
public void BuildChannelWithoutProtectionTokenParameters ()
{
CustomBinding b = new CustomBinding (
new SymmetricSecurityBindingElement (),
new TextMessageEncodingBindingElement (),
new HttpTransportBindingElement ());
b.BuildChannelFactory<IRequestChannel> (new BindingParameterCollection ());
}
示例5: SendChannel
public void SendChannel()
{
Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisSendTransportBinding());
EndpointAddress address = new EndpointAddress("redis://localhost:6379");
IChannelFactory<IDuplexChannel> factory = binding.BuildChannelFactory<IDuplexChannel>();
factory.Open();
IDuplexChannel duplexChannel = factory.CreateChannel(address);
Assert.IsInstanceOf<RedisSendChannel>(duplexChannel);
}
示例6: IRequestChannel_Http_CustomBinding
public static void IRequestChannel_Http_CustomBinding()
{
try
{
BindingElement[] bindingElements = new BindingElement[2];
bindingElements[0] = new TextMessageEncodingBindingElement();
bindingElements[1] = new HttpTransportBindingElement();
CustomBinding binding = new CustomBinding(bindingElements);
// Create the channel factory for the request-reply message exchange pattern.
IChannelFactory<IRequestChannel> factory =
binding.BuildChannelFactory<IRequestChannel>(
new BindingParameterCollection());
factory.Open();
// Create the channel.
IRequestChannel channel = factory.CreateChannel(
new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
channel.Open();
// Create the Message object to send to the service.
Message requestMessage = Message.CreateMessage(
binding.MessageVersion,
action,
new CustomBodyWriter(clientMessage));
// Send the Message and receive the Response.
Message replyMessage = channel.Request(requestMessage);
string replyMessageAction = replyMessage.Headers.Action;
if (!string.Equals(replyMessageAction, action + "Response"))
{
Assert.True(false, String.Format("A response was received from the Service but it was not the expected Action, expected: {0} actual: {1}", action + "Response", replyMessageAction));
}
var replyReader = replyMessage.GetReaderAtBodyContents();
string actualResponse = replyReader.ReadElementContentAsString();
string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
if (!string.Equals(actualResponse, expectedResponse))
{
Assert.True(false, String.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse));
}
replyMessage.Close();
channel.Close();
factory.Close();
}
catch (Exception ex)
{
Assert.True(false, String.Format("Unexpected exception was caught: {0}", ex.ToString()));
}
}
示例7: ReceiveMessage
public void ReceiveMessage()
{
Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisReceiveTransportBinding());
EndpointAddress address = new EndpointAddress("redis://localhost:6379");
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>();
factory.Open();
IRequestChannel channel = factory.CreateChannel(address);
channel.Open();
Message requestMessage = Message.CreateMessage(MessageVersion.Default, "http://tempuri", "Key");
Message replyMessage = channel.Request(requestMessage, TimeSpan.FromSeconds(5));
StringAssert.Contains("Value",replyMessage.GetBody<string>());
}
示例8: SendData
private static void SendData()
{
Console.WriteLine("Sending data:");
Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisSendTransportBinding());
EndpointAddress address = new EndpointAddress("redis://localhost:6379");
IChannelFactory<IDuplexChannel> factory = binding.BuildChannelFactory<IDuplexChannel>();
factory.Open();
IDuplexChannel duplexChannel = factory.CreateChannel(address);
duplexChannel.Open();
Message requestMessage = Message.CreateMessage(MessageVersion.Default, "http://tempuri", "Key:Value");
duplexChannel.Send(requestMessage);
}
示例9: Main
public static void Main ()
{
Console.WriteLine ("Press ENTER when service is ready.");
Console.ReadLine ();
CustomBinding binding = new CustomBinding ();
binding.Elements.Add (new TextMessageEncodingBindingElement ());
binding.Elements.Add (new TcpTransportBindingElement ());
BindingParameterCollection bpcol =
new BindingParameterCollection ();
// using (IChannelFactory<IDuplexSessionChannel> factory =
// binding.BuildChannelFactory<IDuplexSessionChannel>(bpcol))
// {
IChannelFactory<IDuplexSessionChannel> factory =
binding.BuildChannelFactory<IDuplexSessionChannel> (bpcol);
factory.Open ();
IDuplexSessionChannel channel = factory.CreateChannel (
new EndpointAddress ("net.tcp://localhost/"));
channel.Open ();
Message message = Message.CreateMessage (
//channel.Manager.MessageVersion,
MessageVersion.Default,
"Action", "Hello, World, from client side");
channel.Send (message);
message = channel.Receive ();
Console.WriteLine ("Message received.");
Console.WriteLine ("Message action: {0}",
message.Headers.Action);
Console.WriteLine ("Message content: {0}",
message.GetBody<string> ());
message.Close ();
channel.Close ();
factory.Close ();
// }
}
示例10: ReceiveData
private static void ReceiveData()
{
Console.WriteLine("Receiving data:");
Binding binding = new CustomBinding(new RedisMessageBindingElement(), new RedisReceiveTransportBinding());
EndpointAddress address = new EndpointAddress("redis://localhost:6379");
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>();
factory.Open();
IRequestChannel channel = factory.CreateChannel(address);
channel.Open();
Message requestMessage = Message.CreateMessage(MessageVersion.Default, "http://tempuri", "Key");
Message replyMessage = channel.Request(requestMessage, TimeSpan.FromSeconds(5));
using (replyMessage)
{
Console.WriteLine("Processing reply: {0}", replyMessage.Headers.Action);
Console.WriteLine("Reply: {0}", replyMessage.GetBody<string>());
}
}
示例11: RequestReplyChannelFactory_Open
// Create the channel factory and open the channel for the request-reply message exchange pattern.
public static void RequestReplyChannelFactory_Open()
{
try
{
BindingElement[] bindingElements = new BindingElement[2];
bindingElements[0] = new TextMessageEncodingBindingElement();
bindingElements[1] = new HttpTransportBindingElement();
CustomBinding binding = new CustomBinding(bindingElements);
// Create the channel factory
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
factory.Open();
// Create the channel and open it. Success is anything other than an exception.
IRequestChannel channel = factory.CreateChannel(new EndpointAddress("http://localhost/WcfProjectNService.svc"));
channel.Open();
}
catch (Exception ex)
{
Assert.True(false, String.Format("Unexpected exception was caught: {0}", ex.ToString()));
}
}
示例12: CheckDuplicateAuthenticatorTypesClient
public void CheckDuplicateAuthenticatorTypesClient ()
{
SymmetricSecurityBindingElement be =
new SymmetricSecurityBindingElement ();
be.ProtectionTokenParameters =
new X509SecurityTokenParameters ();
be.EndpointSupportingTokenParameters.Endorsing.Add (
new X509SecurityTokenParameters ());
// This causes multiple supporting token authenticator
// of the same type.
be.OptionalEndpointSupportingTokenParameters.Endorsing.Add (
new X509SecurityTokenParameters ());
Binding b = new CustomBinding (be, new HttpTransportBindingElement ());
ClientCredentials cred = new ClientCredentials ();
cred.ClientCertificate.Certificate =
new X509Certificate2 ("Test/Resources/test.pfx", "mono");
IChannelFactory<IReplyChannel> ch = b.BuildChannelFactory<IReplyChannel> (new Uri ("http://localhost:" + NetworkHelpers.FindFreePort ()), cred);
try {
ch.Open ();
} finally {
if (ch.State == CommunicationState.Closed)
ch.Close ();
}
}
示例13: OpenRequestNonAuthenticatable
public void OpenRequestNonAuthenticatable ()
{
SymmetricSecurityBindingElement sbe =
new SymmetricSecurityBindingElement ();
sbe.ProtectionTokenParameters =
new UserNameSecurityTokenParameters ();
Binding binding = new CustomBinding (sbe, new HandlerTransportBindingElement (null));
BindingParameterCollection pl =
new BindingParameterCollection ();
ClientCredentials cred = new ClientCredentials ();
cred.UserName.UserName = "mono";
pl.Add (cred);
IChannelFactory<IRequestChannel> f =
binding.BuildChannelFactory<IRequestChannel> (pl);
f.Open ();
IRequestChannel ch = f.CreateChannel (new EndpointAddress ("stream:dummy"));
try {
ch.Open ();
Assert.Fail ("NotSupportedException is expected.");
} catch (NotSupportedException) {
}
}
示例14: IRequestChannel_Http_CustomBinding
public static void IRequestChannel_Http_CustomBinding()
{
IChannelFactory<IRequestChannel> factory = null;
IRequestChannel channel = null;
Message replyMessage = null;
try
{
// *** SETUP *** \\
BindingElement[] bindingElements = new BindingElement[2];
bindingElements[0] = new TextMessageEncodingBindingElement();
bindingElements[1] = new HttpTransportBindingElement();
CustomBinding binding = new CustomBinding(bindingElements);
// Create the channel factory for the request-reply message exchange pattern.
factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
factory.Open();
// Create the channel.
channel = factory.CreateChannel(new EndpointAddress(Endpoints.DefaultCustomHttp_Address));
channel.Open();
// Create the Message object to send to the service.
Message requestMessage = Message.CreateMessage(
binding.MessageVersion,
action,
new CustomBodyWriter(clientMessage));
// *** EXECUTE *** \\
// Send the Message and receive the Response.
replyMessage = channel.Request(requestMessage);
// *** VALIDATE *** \\
string replyMessageAction = replyMessage.Headers.Action;
Assert.Equal(action + "Response", replyMessageAction);
var replyReader = replyMessage.GetReaderAtBodyContents();
string actualResponse = replyReader.ReadElementContentAsString();
string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
Assert.Equal(expectedResponse, actualResponse);
// *** CLEANUP *** \\
replyMessage.Close();
channel.Close();
factory.Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects(channel, factory);
}
}
示例15: CustomTransportDoesNotRequireMessageEncoding
public void CustomTransportDoesNotRequireMessageEncoding ()
{
ReplyHandler replier = delegate (Message msg) {
resmsg = msg;
};
RequestReceiver receiver = delegate () {
return reqmsg;
};
RequestSender sender = delegate (Message msg) {
reqmsg = msg;
CustomBinding br = new CustomBinding (
new HandlerTransportBindingElement (replier, receiver));
IChannelListener<IReplyChannel> l =
br.BuildChannelListener<IReplyChannel> (
new BindingParameterCollection ());
l.Open ();
IReplyChannel rch = l.AcceptChannel ();
rch.Open ();
Message res = Message.CreateMessage (MessageVersion.Default, "urn:succeeded");
rch.ReceiveRequest ().Reply (res);
rch.Close ();
l.Close ();
return resmsg;
};
CustomBinding bs = new CustomBinding (
new HandlerTransportBindingElement (sender));
IChannelFactory<IRequestChannel> f =
bs.BuildChannelFactory<IRequestChannel> (
new BindingParameterCollection ());
f.Open ();
IRequestChannel ch = f.CreateChannel (new EndpointAddress ("urn:dummy"));
ch.Open ();
Message result = ch.Request (Message.CreateMessage (MessageVersion.Default, "urn:request"));
}