コード例 #1
0
        public static CustomBinding ReplaceEncodingBindingElement(Binding originalBinding, Dictionary <string, string> namespaceToPrefixMapping)
        {
            CustomBinding custom = originalBinding as CustomBinding;

            if (custom == null)
            {
                custom = new CustomBinding(originalBinding);
            }

            for (int i = 0; i < custom.Elements.Count; i++)
            {
                if (custom.Elements[i] is MessageEncodingBindingElement)
                {
                    ReplacePrefixMessageEncodingBindingElement element = new ReplacePrefixMessageEncodingBindingElement((MessageEncodingBindingElement)custom.Elements[i]);
                    foreach (var mapping in namespaceToPrefixMapping)
                    {
                        element.AddNamespaceMapping(mapping.Key, mapping.Value);
                    }

                    custom.Elements[i] = element;
                    break;
                }
            }

            return(custom);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string      baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host        = new ServiceHost(typeof(CalculatorService), new Uri(baseAddress));
            Dictionary <string, string> namespaceToPrefixMapping = new Dictionary <string, string>
            {
                { "http://www.w3.org/2003/05/soap-envelope", "SOAP12-ENV" },
                { "http://www.w3.org/2005/08/addressing", "SOAP12-ADDR" },
            };
            Binding binding = ReplacePrefixMessageEncodingBindingElement.ReplaceEncodingBindingElement(
                new WSHttpBinding(SecurityMode.None),
                namespaceToPrefixMapping);

            host.AddServiceEndpoint(typeof(ICalculator), binding, "");
            host.Open();

            Binding clientBinding = LoggingMessageEncodingBindingElement.ReplaceEncodingBindingElement(
                new WSHttpBinding(SecurityMode.None));
            ChannelFactory <ICalculator> factory = new ChannelFactory <ICalculator>(clientBinding, new EndpointAddress(baseAddress));
            ICalculator proxy = factory.CreateChannel();

            Console.WriteLine(proxy.Add(234, 456));

            ((IClientChannel)proxy).Close();
            factory.Close();
            host.Close();
        }
コード例 #3
0
 private ReplacePrefixMessageEncodingBindingElement(ReplacePrefixMessageEncodingBindingElement other)
 {
     this.inner = other.inner;
     this.namespaceToPrefixMapping = new Dictionary <string, string>(other.namespaceToPrefixMapping);
 }