本文整理汇总了C#中HttpTransportBindingElement类的典型用法代码示例。如果您正苦于以下问题:C# HttpTransportBindingElement类的具体用法?C# HttpTransportBindingElement怎么用?C# HttpTransportBindingElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpTransportBindingElement类属于命名空间,在下文中一共展示了HttpTransportBindingElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JsonRpcHttpBinding
public JsonRpcHttpBinding()
: base()
{
transport = new HttpTransportBindingElement();
encoding = new WebMessageEncodingBindingElement();
encoding.ContentTypeMapper = new JsonRpcRawMapper();
}
示例2: CreateHttpGetChannelDispatcher
private static void CreateHttpGetChannelDispatcher(ServiceHostBase host, Uri listenUri, MetadataSet metadata)
{
//创建Binding
TextMessageEncodingBindingElement messageEncodingElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.None };
HttpTransportBindingElement transportElement = new HttpTransportBindingElement();
Utility.SetPropertyValue(transportElement, "Method", "GET");
Binding binding = new CustomBinding(messageEncodingElement, transportElement);
//创建ChannelListener
IChannelListener listener = binding.BuildChannelListener<IReplyChannel>(listenUri, string.Empty, ListenUriMode.Explicit, new BindingParameterCollection());
ChannelDispatcher dispatcher = new ChannelDispatcher(listener, "ServiceMetadataBehaviorHttpGetBinding", binding) { MessageVersion = binding.MessageVersion };
//创建EndpointDispatcher
EndpointDispatcher endpoint = new EndpointDispatcher(new EndpointAddress(listenUri), "IHttpGetMetadata", "http://www.artech.com/");
//创建DispatchOperation,并设置DispatchMessageFormatter和OperationInvoker
DispatchOperation operation = new DispatchOperation(endpoint.DispatchRuntime, "Get", "*", "*");
operation.Formatter = Utility.CreateInstance<IDispatchMessageFormatter>(MessageOperationFormatterType, Type.EmptyTypes, new object[0]);
MethodInfo method = typeof(IHttpGetMetadata).GetMethod("Get");
operation.Invoker = Utility.CreateInstance<IOperationInvoker>(SyncMethodInvokerType, new Type[] { typeof(MethodInfo) }, new object[] { method });
endpoint.DispatchRuntime.Operations.Add(operation);
//设置SingletonInstanceContext和InstanceContextProvider
MetadataProvisionService serviceInstance = new MetadataProvisionService(metadata);
endpoint.DispatchRuntime.SingletonInstanceContext = new InstanceContext(host, serviceInstance);
endpoint.DispatchRuntime.InstanceContextProvider = Utility.CreateInstance<IInstanceContextProvider>(SingletonInstanceContextProviderType, new Type[] { typeof(DispatchRuntime) }, new object[] { endpoint.DispatchRuntime });
dispatcher.Endpoints.Add(endpoint);
//设置ContractFilter和AddressFilter
endpoint.ContractFilter = new MatchAllMessageFilter();
endpoint.AddressFilter = new MatchAllMessageFilter();
host.ChannelDispatchers.Add(dispatcher);
}
示例3: GetBinding
public static CustomBinding GetBinding()
{
// Same binding should be used in both service and service client.
//var binding = new BasicHttpBinding();
//binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
//SetTimeOuts(binding);
//return binding;
// Instantiate message encoding element and configure
TextMessageEncodingBindingElement text = new TextMessageEncodingBindingElement();
text.MessageVersion = MessageVersion.Soap11;
text.ReaderQuotas.MaxStringContentLength = int.MaxValue;
// Instantiate transport element and configure
HttpTransportBindingElement http = new HttpTransportBindingElement();
http.TransferMode = TransferMode.Buffered;
http.UseDefaultWebProxy = true;
CustomBinding binding = new CustomBinding();
binding.Name = "MonoscapeHttpBinding";
binding.Elements.Add(text);
binding.Elements.Add(http);
SetTimeOuts(binding);
return binding;
}
示例4: ConfigureAuthentication
private void ConfigureAuthentication(HttpTransportBindingElement http)
{
http.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(this.clientCredentialType);
http.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(this.proxyCredentialType);
http.Realm = this.Realm;
http.ExtendedProtectionPolicy = this.extendedProtectionPolicy;
}
示例5: DisableAuthentication
private void DisableAuthentication(HttpTransportBindingElement http)
{
http.AuthenticationScheme = AuthenticationSchemes.Anonymous;
http.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
http.Realm = "";
http.ExtendedProtectionPolicy = this.extendedProtectionPolicy;
}
示例6: CanBuildChannelFactory
public void CanBuildChannelFactory ()
{
// with HttpTransport
var m = new WebMessageEncodingBindingElement ();
Assert.IsTrue (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#1");
Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#2");
Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#3");
Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#4");
// actually they are from transport
var h = new HttpTransportBindingElement ();
Assert.IsTrue (h.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#5");
Assert.IsFalse (h.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#6");
Assert.IsFalse (h.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#7");
Assert.IsFalse (h.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#8");
// with TcpTransport
Assert.IsFalse (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#9");
Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#10");
Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#11");
Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#12");
// ... yes, actually they are from transport
var t = new TcpTransportBindingElement ();
Assert.IsFalse (t.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#13");
Assert.IsFalse (t.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#14");
Assert.IsFalse (t.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#15");
Assert.IsFalse (t.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#16");
}
示例7: InitializeFrom
private void InitializeFrom(HttpTransportBindingElement transport, MessageEncodingBindingElement encoding, System.ServiceModel.Channels.TransactionFlowBindingElement txFlow, System.ServiceModel.Channels.ReliableSessionBindingElement session)
{
this.BypassProxyOnLocal = transport.BypassProxyOnLocal;
this.HostNameComparisonMode = transport.HostNameComparisonMode;
this.MaxBufferPoolSize = transport.MaxBufferPoolSize;
this.MaxReceivedMessageSize = transport.MaxReceivedMessageSize;
this.ProxyAddress = transport.ProxyAddress;
this.UseDefaultWebProxy = transport.UseDefaultWebProxy;
if (encoding is TextMessageEncodingBindingElement)
{
this.MessageEncoding = WSMessageEncoding.Text;
TextMessageEncodingBindingElement element = (TextMessageEncodingBindingElement) encoding;
this.TextEncoding = element.WriteEncoding;
this.ReaderQuotas = element.ReaderQuotas;
}
else if (encoding is MtomMessageEncodingBindingElement)
{
this.messageEncoding = WSMessageEncoding.Mtom;
MtomMessageEncodingBindingElement element2 = (MtomMessageEncodingBindingElement) encoding;
this.TextEncoding = element2.WriteEncoding;
this.ReaderQuotas = element2.ReaderQuotas;
}
this.TransactionFlow = txFlow.Transactions;
this.reliableSession.Enabled = session != null;
if (session != null)
{
this.session.InactivityTimeout = session.InactivityTimeout;
this.session.Ordered = session.Ordered;
}
}
示例8: 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);
IChannelListener<IReplyChannel> listener=binding.BuildChannelListener<IReplyChannel>(new Uri("http://localhost:9090/RequestReplyService"),new BindingParameterCollection());
listener.Open();
IReplyChannel replyChannel = listener.AcceptChannel();
replyChannel.Open();
Console.WriteLine("starting to receive message....");
RequestContext requestContext = replyChannel.ReceiveRequest();
Console.WriteLine("Received a Message, action:{0},body:{1}", requestContext.RequestMessage.Headers.Action,
requestContext.RequestMessage.GetBody<string>());
Message message = Message.CreateMessage(binding.MessageVersion, "response", "response Message");
requestContext.Reply(message);
requestContext.Close();
replyChannel.Close();
listener.Close();
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
finally {
Console.Read();
}
}
示例9: 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();
}
}
示例10: Main
public static void Main ()
{
HttpTransportBindingElement el =
new HttpTransportBindingElement ();
BindingContext bc = new BindingContext (
new CustomBinding (),
new BindingParameterCollection (),
new Uri ("http://localhost:37564"),
String.Empty, ListenUriMode.Explicit);
IChannelListener<IReplyChannel> listener =
el.BuildChannelListener<IReplyChannel> (bc);
listener.Open ();
IReplyChannel reply = listener.AcceptChannel ();
reply.Open ();
if (!reply.WaitForRequest (TimeSpan.FromSeconds (10))) {
Console.WriteLine ("No request reached here.");
return;
}
Console.WriteLine ("Receiving request ...");
RequestContext ctx = reply.ReceiveRequest ();
if (ctx == null)
return;
Console.WriteLine ("Starting reply ...");
ctx.Reply (Message.CreateMessage (MessageVersion.Default, "Ack"));
}
示例11: Main
// Host the service within this EXE console application.
public static void Main()
{
Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");
// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
// Create a custom binding containing two binding elements
ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement();
reliableSession.Ordered = true;
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
CustomBinding binding = new CustomBinding(reliableSession, httpTransport);
// Add an endpoint using that binding
serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, "");
// Open the ServiceHost to create listeners and start listening for messages.
serviceHost.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
}
}
示例12: GetSecurityModeFromTransport
private static bool GetSecurityModeFromTransport(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity, out UnifiedSecurityMode mode)
{
mode = UnifiedSecurityMode.None;
if (http == null)
{
return false;
}
if (http is HttpsTransportBindingElement)
{
mode = UnifiedSecurityMode.TransportWithMessageCredential | UnifiedSecurityMode.Transport;
BasicHttpSecurity.EnableTransportSecurity((HttpsTransportBindingElement) http, transportSecurity);
}
else if (HttpTransportSecurity.IsDisabledTransportAuthentication(http))
{
mode = UnifiedSecurityMode.Message | UnifiedSecurityMode.None;
}
else
{
if (!BasicHttpSecurity.IsEnabledTransportAuthentication(http, transportSecurity))
{
return false;
}
mode = UnifiedSecurityMode.TransportCredentialOnly;
}
return true;
}
示例13: Main
public static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8000/servicesamplemodel/service");
using (ServiceHost host = new ServiceHost(typeof(Service), baseAddress))
{
ReliableSessionBindingElement reliableBinding = new ReliableSessionBindingElement();
reliableBinding.Ordered = true;
HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
httpBindingElement.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
httpBindingElement.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
CustomBinding customBinding = new CustomBinding(reliableBinding, httpBindingElement);
host.AddServiceEndpoint(typeof(ICalculator), customBinding, "");
host.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
}
}
示例14: Main
public static void Main ()
{
SymmetricSecurityBindingElement sbe =
new SymmetricSecurityBindingElement ();
sbe.ProtectionTokenParameters =
new SslSecurityTokenParameters ();
ServiceHost host = new ServiceHost (typeof (Foo));
HttpTransportBindingElement hbe =
new HttpTransportBindingElement ();
CustomBinding binding = new CustomBinding (sbe, hbe);
binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
host.AddServiceEndpoint ("IFoo",
binding, new Uri ("http://localhost:8080"));
ServiceCredentials cred = new ServiceCredentials ();
cred.SecureConversationAuthentication.SecurityStateEncoder =
new MyEncoder ();
cred.ServiceCertificate.Certificate =
new X509Certificate2 ("test.pfx", "mono");
cred.ClientCertificate.Authentication.CertificateValidationMode =
X509CertificateValidationMode.None;
host.Description.Behaviors.Add (cred);
host.Description.Behaviors.Find<ServiceDebugBehavior> ()
.IncludeExceptionDetailInFaults = true;
// foreach (ServiceEndpoint se in host.Description.Endpoints)
// se.Behaviors.Add (new StdErrInspectionBehavior ());
ServiceMetadataBehavior smb = new ServiceMetadataBehavior ();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl");
host.Description.Behaviors.Add (smb);
host.Open ();
Console.WriteLine ("Hit [CR] key to close ...");
Console.ReadLine ();
host.Close ();
}
示例15: Main
public static void Main ()
{
HttpTransportBindingElement el =
new HttpTransportBindingElement ();
IChannelFactory<IRequestChannel> factory =
el.BuildChannelFactory<IRequestChannel> (
new BindingContext (new CustomBinding (),
new BindingParameterCollection ()));
factory.Open ();
IRequestChannel request = factory.CreateChannel (
new EndpointAddress ("http://localhost:37564"));
request.Open ();
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
Message.CreateMessage (MessageVersion.Default, "Echo")
.WriteMessage (w);
}
Console.WriteLine ();
Message msg = request.Request (
Message.CreateMessage (MessageVersion.Default, "Echo"),
TimeSpan.FromSeconds (15));
using (XmlWriter w = XmlWriter.Create (Console.Out)) {
msg.WriteMessage (w);
}
}