none
How to add WCF binding property dunamically using c# RRS feed

  • Question

  • Hi,  

    We are working on a HTML5 MVC application with WCF service (CustomBinding). we have created serviceAgent.cs file, where we have defined all the binding property and loading it dynamically. Here unable to adde all the property

    Here is our code 
    -----------------------------
    CustomBinding binding = null;
    binding = new CustomBinding( new BinaryMessageEncodingBindingElement( ), new HttpTransportBindingElement( )
                    { 
                        MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, TransferMode = TransferMode.StreamedResponse 
                    } 
                    );

                    //Timeout settings are kept by praveen on 21-09-2012 to resolve Timeout Exceptions when there are long operations a specially in playback module.
                    binding.CloseTimeout = TimeSpan.FromMinutes( 15 );
                    binding.OpenTimeout = TimeSpan.FromMinutes( 15 );
                    binding.ReceiveTimeout = TimeSpan.FromMinutes( 15 );
                    binding.SendTimeout = TimeSpan.FromMinutes( 15 ); 

    Is there any way to add all the binding property. Please provide a sample will be great help.

    we want to add all these property available in below xml.

    <binding name="customBinding" closeTimeout="00:01:00" openTimeout="00:15:00" receiveTimeout="00:15:00" sendTimeout="00:15:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedResponse" useDefaultWebProxy="true">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                <message clientCredentialType="UserName" algorithmSuite="Default"/>
              </security>
            </binding>

    Thanks,
    Bijay
    Thursday, April 24, 2014 6:47 AM

Answers

  • Hi,

    For creating the custom binding in code, then it will be something like this:

    BinaryMessageEncodingBindingElement binaryEncoding = new BinaryMessageEncodingBindingElement();
                binaryEncoding.ReaderQuotas.MaxDepth = int.MaxValue;
                binaryEncoding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                binaryEncoding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                binaryEncoding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                binaryEncoding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;                    
                CustomBinding binding = null;
                binding = new CustomBinding(binaryEncoding, new HttpTransportBindingElement()
                {
                    MaxBufferSize = int.MaxValue,
                    MaxReceivedMessageSize = int.MaxValue,
                    TransferMode = TransferMode.StreamedResponse,
                    UseDefaultWebProxy = true,
                    BypassProxyOnLocal=false,
                    HostNameComparisonMode=HostNameComparisonMode.StrongWildcard,
                    AllowCookies=false,                
    
                });
               
                binding.CloseTimeout = TimeSpan.FromMinutes(15);
                binding.OpenTimeout = TimeSpan.FromMinutes(15);
                binding.ReceiveTimeout = TimeSpan.FromMinutes(15);
                binding.SendTimeout = TimeSpan.FromMinutes(15);
    
            }

    Also please try to check these similar threads:

    #WCF CustomBinding dynamically in code:http://social.msdn.microsoft.com/Forums/vstudio/en-US/dcf8dcb1-d9d8-44c0-9415-d985b2d19300/help-me-programmatically-create-a-custom-binding?forum=wcf .

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/2205b22c-b582-4771-a361-ee9b85fc0493/wcf-custombinding-dynamically?forum=wcf .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, April 25, 2014 2:55 AM
    Moderator