/// <summary> /// Initializes a new instance of the WOPIMessageEncodingBindingElement class. This is the copy constructor. /// </summary> /// <param name="binding">Specify the copy binding element.</param> private WOPIMessageEncodingBindingElement(WOPIMessageEncodingBindingElement binding) : this() { this.MessageVersion = binding.MessageVersion; this.Encoding = binding.Encoding; binding.ReaderQuotas.CopyTo(this.ReaderQuotas); }
/// <summary> /// This method is used to create the WOPIMessageEncodingBindingElement instance. /// </summary> /// <returns>Return the created WOPIMessageEncodingBindingElement instance.</returns> protected override System.ServiceModel.Channels.BindingElement CreateBindingElement() { WOPIMessageEncodingBindingElement bindingElement = new WOPIMessageEncodingBindingElement(); this.ApplyConfiguration(bindingElement); return(bindingElement); }
/// <summary> /// This method is used to apply the configuration to WOPIMessageEncodingBindingElement. /// </summary> /// <param name="bindingElement">Specify the WOPIMessageEncodingBindingElement type instance.</param> public override void ApplyConfiguration(BindingElement bindingElement) { base.ApplyConfiguration(bindingElement); WOPIMessageEncodingBindingElement be = (WOPIMessageEncodingBindingElement)bindingElement; // Take the soap11 as the default message version. be.MessageVersion = MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap11, AddressingVersion.None); be.Encoding = this.Encoding; this.ApplyReaderQuotas(be.ReaderQuotas); }
/// <summary> /// This method is used to create communication channel based on the specified context. /// </summary> /// <typeparam name="T">Specify the type of the channel.</typeparam> /// <param name="context">Specify the context.</param> /// <returns>Return the created new channel instance.</returns> public T CreateChannel <T>(SharedContext context) where T : IClientChannel { if (!this.cached.ContainsKey(context)) { lock (lockObject) { if (!this.cached.ContainsKey(context)) { ChannelFactory <T> cachedItem = new ChannelFactory <T>(context.EndpointConfigurationName, new EndpointAddress(context.TargetUrl)); // Try to get the encoding. WOPIMessageEncodingBindingElement messageEncodingBinding = cachedItem.Endpoint.Binding.CreateBindingElements().OfType <WOPIMessageEncodingBindingElement>().FirstOrDefault(); if (messageEncodingBinding != null && messageEncodingBinding.Encoding != null) { context.AddOrUpdate("Encoding", messageEncodingBinding.Encoding); } cachedItem.Endpoint.Behaviors.Add(new MessageInspector(context)); // Remove the possible visual studio wcf debug behaviors. var removeDiagnosticsEndPoint = cachedItem.Endpoint.Behaviors.Where(behavior => string.Compare("Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior", behavior.GetType().FullName, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault(); if (removeDiagnosticsEndPoint != null) { cachedItem.Endpoint.Behaviors.Remove(removeDiagnosticsEndPoint); } // Change the credential this.ChangeCredential(cachedItem, context); cachedItem.Faulted += new EventHandler(this.ChannelFactory_Faulted); cachedItem.Open(); this.cached.Add(context, cachedItem); } } } ChannelFactory <T> channelFactory = this.cached[context] as ChannelFactory <T>; T channel = channelFactory.CreateChannel(); channel.Faulted += new EventHandler(this.Channel_Faulted); channel.Open(); return(channel); }
/// <summary> /// This method is used to calculate the message size. /// </summary> /// <param name="message">Specify the request message.</param> /// <returns>Return the size of the request message.</returns> private int SizeOfWOPIMessage(Message message) { // Create an WOPI encoder WOPIMessageEncodingBindingElement element = new WOPIMessageEncodingBindingElement(); element.MessageVersion = message.Version; element.Encoding = this.context.GetValueOrDefault <string>("Encoding", "utf-8"); WOPIMessageEncoderFactory factory = (WOPIMessageEncoderFactory)element.CreateMessageEncoderFactory(); MessageEncoder encoder = factory.Encoder; // Write the message and return its length int size; using (MemoryStream stream = new MemoryStream()) { encoder.WriteMessage(message, stream); size = (int)stream.Length; } return(size); }