本文整理汇总了C#中System.ServiceModel.BasicHttpBinding.BuildChannelFactory方法的典型用法代码示例。如果您正苦于以下问题:C# BasicHttpBinding.BuildChannelFactory方法的具体用法?C# BasicHttpBinding.BuildChannelFactory怎么用?C# BasicHttpBinding.BuildChannelFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.BasicHttpBinding
的用法示例。
在下文中一共展示了BasicHttpBinding.BuildChannelFactory方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildChannelFactoryForHttpEndpoint
public void BuildChannelFactoryForHttpEndpoint ()
{
var b = new BasicHttpBinding ();
b.Security.Mode = BasicHttpSecurityMode.Transport;
var cf = b.BuildChannelFactory<IRequestChannel> ();
cf.Open ();
cf.CreateChannel (new EndpointAddress ("http://localhost:8080"));
}
示例2: Create_HttpBinding_SecurityMode_Without_SecurityBindingElement
public static void Create_HttpBinding_SecurityMode_Without_SecurityBindingElement(BasicHttpSecurityMode securityMode)
{
BasicHttpBinding binding = new BasicHttpBinding(securityMode);
var bindingElements = binding.CreateBindingElements();
var securityBindingElement = bindingElements.FirstOrDefault(x => x is SecurityBindingElement) as SecurityBindingElement;
Assert.True(securityBindingElement == null, string.Format("securityBindingElement should be null when BasicHttpSecurityMode is '{0}'", securityMode));
Assert.True(binding.CanBuildChannelFactory<IRequestChannel>(), string.Format("CanBuildChannelFactory should return true for BasicHttpSecurityMode:'{0}'", securityMode));
binding.BuildChannelFactory<IRequestChannel>();
}
示例3: Main
static void Main(string[] args)
{
Uri listenUri = new Uri("http://127.0.0.1:9999/listener");
Binding binding = new BasicHttpBinding();
IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>();
channelFactory.Open();
IRequestChannel channel = channelFactory.CreateChannel(new EndpointAddress(listenUri));
channel.Open();
Message replyMessage = channel.Request(CreateRequestMessage(binding));
Console.WriteLine("the reply message\n{0}", replyMessage);
Console.Read();
}
示例4: Main
static void Main(string[] args)
{
EndpointAddress address = new EndpointAddress("http://127.0.0.1:9999/messagingviabinding");
BasicHttpBinding binding = new BasicHttpBinding();
IChannelFactory<IRequestChannel> chananelFactory = binding.BuildChannelFactory<IRequestChannel>();
chananelFactory.Open();
IRequestChannel channel = chananelFactory.CreateChannel(address);
channel.Open();
Message requestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://artech/messagingviabinding", "The is a request message manually created for the purpose of testing.");
Message replyMessage = channel.Request(requestMessage);
Console.WriteLine("Receive a reply message:\n{0}", replyMessage);
channel.Close();
chananelFactory.Close();
Console.Read();
}
示例5: IRequestChannel_Http_BasicHttpBinding
public static void IRequestChannel_Http_BasicHttpBinding()
{
IChannelFactory<IRequestChannel> factory = null;
IRequestChannel channel = null;
Message replyMessage = null;
try
{
// *** SETUP *** \\
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
// Create the channel factory
factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
factory.Open();
// Create the channel.
channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
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 *** \\
// BasicHttpBinding uses SOAP1.1 which doesn't return the Headers.Action property in the Response
// Therefore not validating this property as we do in the test "InvokeIRequestChannelCreatedViaBinding"
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);
}
}
示例6: IRequestChannel_Http_BasicHttpBinding
public static void IRequestChannel_Http_BasicHttpBinding()
{
try
{
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
// Create the channel factory
IChannelFactory<IRequestChannel> factory =
binding.BuildChannelFactory<IRequestChannel>(
new BindingParameterCollection());
factory.Open();
// Create the channel.
IRequestChannel channel = factory.CreateChannel(
new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
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);
// BasicHttpBinding uses SOAP1.1 which doesn't return the Headers.Action property in the Response
// Therefore not validating this property as we do in the test "InvokeIRequestChannelCreatedViaBinding"
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: Main
static void Main(string[] args)
{
Uri listenUri = new Uri("http://127.0.0.1:3721/listener");
Binding binding = new BasicHttpBinding();
//创建、开启信道工厂
IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>();
channelFactory.Open();
//创建、开启请求信道
IRequestChannel channel = channelFactory.CreateChannel(new EndpointAddress(listenUri));
channel.Open();
//发送请求消息,接收回复消息
Message replyMessage = channel.Request(CreateRequestMessage(binding));
Console.WriteLine(replyMessage);
Console.Read();
}
示例8: Main
static void Main(string[] args)
{
EndpointAddress address = new EndpointAddress("http://localhost:1111/MessageViaBinding");
var binding = new BasicHttpBinding();
var channelFactory = binding.BuildChannelFactory<IRequestChannel>();
channelFactory.Open();
var channel = channelFactory.CreateChannel(address);
channel.Open();
var message = Message.CreateMessage(MessageVersion.Soap11, "http://MessageViaBinding", "The is a request message manually created for the purpose of testing.");
Message replayMessage=channel.Request(message);
Console.WriteLine("Receive a reply message:\n{0}", replayMessage);
channel.Close();
channelFactory.Close();
Console.ReadLine();
}
示例9: Main
public static void Main ()
{
Binding b = new BasicHttpBinding ();
IChannelFactory<IRequestChannel> cf = b.BuildChannelFactory<IRequestChannel> (
new BindingParameterCollection ());
cf.Open ();
IRequestChannel req = cf.CreateChannel (
new EndpointAddress ("http://localhost:8080/"));
Console.WriteLine (req.State);
req.Open ();
Message msg = Message.CreateMessage (MessageVersion.Soap11, "http://tempuri.org/IFoo/ProcessMessage", new EchoType ("hoge"));
Message ret = req.Request (msg);
Console.WriteLine (req.State);
var p = ret.Properties [HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
Console.WriteLine (p.StatusCode);
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
ret.WriteMessage (w);
}
}
示例10: Main
public static void Main ()
{
Binding b = new BasicHttpBinding ();
IChannelFactory<IRequestChannel> cf = b.BuildChannelFactory<IRequestChannel> (
new BindingParameterCollection ());
cf.Open ();
IRequestChannel req = cf.CreateChannel (
new EndpointAddress ("http://localhost:8080/"));
Console.WriteLine (req.State);
req.Open ();
Message msg = Message.CreateMessage (MessageVersion.Soap11, "http://tempuri.org/IFoo/Echo", new EchoType ("hoge"));
//Message ret = req.Request (msg);
IAsyncResult result = req.BeginRequest (msg, null, null);
//return;
Message ret = req.EndRequest (result);
Console.WriteLine (req.State);
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
ret.WriteMessage (w);
}
}
示例11: Custom_Message_RoundTrips
public static void Custom_Message_RoundTrips()
{
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
// Create the channel factory
IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(new BindingParameterCollection());
factory.Open();
// Create the channel.
IRequestChannel channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_Basic));
channel.Open();
// Create the Message object to send to the service.
using (Message requestMessage = Message.CreateMessage(
binding.MessageVersion,
action,
new CustomBodyWriter(clientMessage)))
{
// Send the Message and receive the Response.
using (Message replyMessage = channel.Request(requestMessage))
{
Assert.False(replyMessage.IsFault);
Assert.False(replyMessage.IsEmpty);
Assert.Equal(MessageState.Created, replyMessage.State);
Assert.Equal(MessageVersion.Soap11, replyMessage.Version);
var replyReader = replyMessage.GetReaderAtBodyContents();
string actualResponse = replyReader.ReadElementContentAsString();
string expectedResponse = "Test Custom_Message_RoundTrips.[service] Request received, this is my Reply.";
Assert.True(string.Equals(actualResponse, expectedResponse),
string.Format("Actual MessageBodyContent from service did not match the expected MessageBodyContent, expected: {0} actual: {1}", expectedResponse, actualResponse));
}
}
channel.Close();
factory.Close();
}
示例12: Main
public static void Main ()
{
var b = new BasicHttpBinding ();
b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
var cc = new ClientCredentials ();
cc.UserName.UserName = "mono";
IChannelFactory<IRequestChannel> cf = b.BuildChannelFactory<IRequestChannel> (cc);
cf.Open ();
IRequestChannel req = cf.CreateChannel (
new EndpointAddress ("http://localhost:8080/"));
Console.WriteLine (cf.GetProperty<ClientCredentials> ());
req.Open ();
Message msg = Message.CreateMessage (MessageVersion.Soap11, "http://tempuri.org/IFoo/Echo", new EchoType ("hoge"));
//Message ret = req.Request (msg);
IAsyncResult result = req.BeginRequest (msg, null, null);
//return;
Message ret = req.EndRequest (result);
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
ret.WriteMessage (w);
}
}
示例13: IDuplexSessionChannel_Http_BasicHttpBinding
public static void IDuplexSessionChannel_Http_BasicHttpBinding()
{
#if FULLXUNIT_NOTSUPPORTED
bool root_Certificate_Installed = Root_Certificate_Installed();
if (!root_Certificate_Installed)
{
Console.WriteLine("---- Test SKIPPED --------------");
Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
return;
}
#endif
IChannelFactory<IDuplexSessionChannel> factory = null;
IDuplexSessionChannel channel = null;
Message replyMessage = null;
try
{
// *** SETUP *** \\
BasicHttpBinding binding = new BasicHttpBinding();
// Create the channel factory
factory = binding.BuildChannelFactory<IDuplexSessionChannel>(new BindingParameterCollection());
factory.Open();
// Create the channel.
channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps));
channel.Open();
// Create the Message object to send to the service.
Message requestMessage = Message.CreateMessage(
binding.MessageVersion,
action,
new CustomBodyWriter(clientMessage));
requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid());
// *** EXECUTE *** \\
// Send the Message and receive the Response.
channel.Send(requestMessage);
replyMessage = channel.Receive(TimeSpan.FromSeconds(5));
// *** VALIDATE *** \\
// If the incoming Message did not contain the same UniqueId used for the MessageId of the outgoing Message we would have received a Fault from the Service
Assert.Equal(requestMessage.Headers.MessageId.ToString(), replyMessage.Headers.RelatesTo.ToString());
// Validate the Response
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);
}
}
示例14: WcfRoutingService
static WcfRoutingService()
{
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
_factory = binding.BuildChannelFactory<IRequestChannel>();
_factory.Open();
}