XmlRpcEncodingBindingElement.cs :  » Bloggers » dasBlog » Microsoft » ServiceModel » Samples » XmlRpc » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » Microsoft » ServiceModel » Samples » XmlRpc » XmlRpcEncodingBindingElement.cs

//  Copyright (c) Microsoft Corporation.  All Rights Reserved.

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel.Channels;
using System.Xml;
using System.ServiceModel;

namespace Microsoft.ServiceModel.Samples.XmlRpc{
    public class XmlRpcMessageEncodingBindingElement : MessageEncodingBindingElement
    {
        // Fields
        private int maxReadPoolSize;
        private int maxWritePoolSize;
        private XmlDictionaryReaderQuotas readerQuotas;

        // Methods
        public XmlRpcMessageEncodingBindingElement() : this(MessageVersion.None,Encoding.UTF8)
        {
        }

        private XmlRpcMessageEncodingBindingElement(XmlRpcMessageEncodingBindingElement elementToBeCloned) : base(elementToBeCloned)
        {
            this.maxReadPoolSize = elementToBeCloned.maxReadPoolSize;
            this.maxWritePoolSize = elementToBeCloned.maxWritePoolSize;
            this.readerQuotas = new XmlDictionaryReaderQuotas();
            elementToBeCloned.readerQuotas.CopyTo(this.readerQuotas);
        }

        public XmlRpcMessageEncodingBindingElement(MessageVersion messageVersion, Encoding writeEncoding)
        {
            this.maxReadPoolSize = 0x40;
            this.maxWritePoolSize = 0x10;
            this.readerQuotas = new XmlDictionaryReaderQuotas();
            XmlRpcMessageEncoder.GetDefaultReaderQuotas().CopyTo(this.readerQuotas);
        }

        public override BindingElement Clone()
        {
            return new XmlRpcMessageEncodingBindingElement(this);
        }

         public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
        {
            context.BindingParameters.Add(this);
            return context.BuildInnerChannelFactory<TChannel>();
        }

        public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context) 
        {
            context.BindingParameters.Add(this);
            return context.BuildInnerChannelListener<TChannel>();
        }

        public override bool CanBuildChannelListener<TChannel>(BindingContext context) 
        {
            context.BindingParameters.Add(this);
            return context.CanBuildInnerChannelListener<TChannel>();
        }

        public override MessageEncoderFactory CreateMessageEncoderFactory()
        {
            return new XmlRpcMessageEncoderFactory(this.MaxReadPoolSize, this.MaxWritePoolSize, this.ReaderQuotas);
        }

        public override T GetProperty<T>(BindingContext context) 
        {
            if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
            {
                return this.readerQuotas as T;
            }
            if (typeof(T) == typeof(MessageVersion))
            {
                return MessageVersion as T;
            }
            return base.GetProperty<T>(context);
        }
        
        //CFV:internal bool xIsMatch(BindingElement bindingElement)
        //{
        //    if (!base.IsMatch(bindingElement))
        //    {
        //        return false;
        //    }
        //    XmlRpcMessageEncodingBindingElement messageEncodingElement = bindingElement as XmlRpcMessageEncodingBindingElement;
        //    if (messageEncodingElement == null)
        //    {
        //        return false;
        //    }
        //    if (this.maxReadPoolSize != messageEncodingElement.MaxReadPoolSize)
        //    {
        //        return false;
        //    }
        //    if (this.maxWritePoolSize != messageEncodingElement.MaxWritePoolSize)
        //    {
        //        return false;
        //    }
        //    if (this.readerQuotas.MaxStringContentLength != messageEncodingElement.ReaderQuotas.MaxStringContentLength)
        //    {
        //        return false;
        //    }
        //    if (this.readerQuotas.MaxArrayLength != messageEncodingElement.ReaderQuotas.MaxArrayLength)
        //    {
        //        return false;
        //    }
        //    if (this.readerQuotas.MaxBytesPerRead != messageEncodingElement.ReaderQuotas.MaxBytesPerRead)
        //    {
        //        return false;
        //    }
        //    if (this.readerQuotas.MaxDepth != messageEncodingElement.ReaderQuotas.MaxDepth)
        //    {
        //        return false;
        //    }
        //    if (this.readerQuotas.MaxNameTableCharCount != messageEncodingElement.ReaderQuotas.MaxNameTableCharCount)
        //    {
        //        return false;
        //    }
        //    return true;
        //}

        
        // Properties
        public int MaxReadPoolSize
        {
            get
            {
                return this.maxReadPoolSize;
            }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentOutOfRangeException("value", value, "");
                }
                this.maxReadPoolSize = value;
            }
        }

        public int MaxWritePoolSize
        {
            get
            {
                return this.maxWritePoolSize;
            }
            set
            {
                if (value <= 0)
                {
                    throw new ArgumentOutOfRangeException("value", value, "");
                }
                this.maxWritePoolSize = value;
            }
        }

        public XmlDictionaryReaderQuotas ReaderQuotas
        {
            get
            {
                return this.readerQuotas;
            }
        }

        public override MessageVersion MessageVersion
        {
            get
            {
                return MessageVersion.None;
            }
            set
            {
                if (value != MessageVersion.None)
                    throw new ArgumentOutOfRangeException();
            }
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.