none
Call HTTPS wcf service using programmatically created binding

    Question

  • Hi

    i want to call HTTPS WCF services.

    When we r calling like this..

     SmartPayments2SoapClient client = new SmartPayments2SoapClient();

    it is working correctly ... .

    but in my scenario i dont want to use default binding ...

    Binding must be created programmatically .... but in this, my services is secure mean its run on HTTPS...

    Please suggest me code where i can create Binding programmatically ...

    here is the app.config custom binding...

     <customBinding>
                    <binding name="SmartPayments2Soap12">
                        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                            messageVersion="Soap12" writeEncoding="utf-8">
                            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        </textMessageEncoding>
                        <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                            maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                            useDefaultWebProxy="true" requireClientCertificate="false" />
                    </binding>
                </customBinding>

    I want this to be converted in C# programm...

    i have tried this...

    SecurityBindingElement securityElement = SecurityBindingElement.CreateSslNegotiationBindingElement(false);
                    HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
                    httpsTransport.AllowCookies = false;
                    httpsTransport.BypassProxyOnLocal = false;
                    httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    httpsTransport.MaxBufferSize = 65536;
                    httpsTransport.MaxBufferPoolSize = 524288;
                    httpsTransport.MaxReceivedMessageSize = 65536;
                    httpsTransport.TransferMode = TransferMode.Buffered;
                    httpsTransport.UseDefaultWebProxy = true;
                    httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
    
                    httpsTransport.ManualAddressing = false;
                    httpsTransport.AllowCookies = false;
                    httpsTransport.BypassProxyOnLocal = false;
                    //httpsTransport.DecompressionEnabled = true;
                    httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    httpsTransport.KeepAliveEnabled = true;
                    httpsTransport.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
                    httpsTransport.Realm = "";
                    httpsTransport.TransferMode = TransferMode.Buffered;
                    httpsTransport.UnsafeConnectionNtlmAuthentication = false;
                    httpsTransport.UseDefaultWebProxy = true;
    
                    CustomBinding binding = new CustomBinding(securityElement, httpsTransport);
    
                    EndpointAddress remoteAddress = new EndpointAddress("https://Mysite/Payments/transact2.asmx");
    
    
                    SmartPayments2SoapClient client = new SmartPayments2SoapClient(binding, remoteAddress);

    Please suggest on this.....

    Friday, February 08, 2013 1:54 PM

Answers

  • hey i found the ans....

    here is the code which work for me....

     HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
                    httpsTransport.AllowCookies = false;
                    httpsTransport.BypassProxyOnLocal = false;
                    httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    httpsTransport.MaxBufferSize = 65536;
                    httpsTransport.MaxBufferPoolSize = 524288;
                    httpsTransport.MaxReceivedMessageSize = 65536;
                    httpsTransport.TransferMode = TransferMode.Buffered;
                    httpsTransport.UseDefaultWebProxy = true;
                    httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
    
                    httpsTransport.ManualAddressing = false;
                    httpsTransport.AllowCookies = false;
                    httpsTransport.BypassProxyOnLocal = false;
                    //httpsTransport.DecompressionEnabled = true;
                    httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    httpsTransport.KeepAliveEnabled = true;
                    httpsTransport.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
                    httpsTransport.Realm = "";
                    httpsTransport.TransferMode = TransferMode.Buffered;
                    httpsTransport.UnsafeConnectionNtlmAuthentication = false;
                    httpsTransport.UseDefaultWebProxy = true;           
    
                    CustomBinding binding1 = new CustomBinding();
                    TextMessageEncodingBindingElement oTextMessageEncod = new TextMessageEncodingBindingElement();
                    oTextMessageEncod.MaxReadPoolSize = 64;
                    oTextMessageEncod.MaxWritePoolSize = 16;
                    oTextMessageEncod.MessageVersion = MessageVersion.Soap12;
                    oTextMessageEncod.WriteEncoding = Encoding.UTF8;
    
                    binding1.Elements.Add(oTextMessageEncod);
                    binding1.Elements.Add(httpsTransport);
    
                    EndpointAddress remoteAddress = new EndpointAddress("https://example.com/Payments/transact2.asmx");
                    
    
                    SmartPayments2SoapClient client = new SmartPayments2SoapClient(binding1, remoteAddress);
                  
                    {
                        client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                    }
    
                    response1 = client.GetInfo("", "", "", "");


    Saturday, February 09, 2013 7:22 AM

All replies

  • Is any one who can assist me in this?
    Saturday, February 09, 2013 4:02 AM
  • hey i found the ans....

    here is the code which work for me....

     HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
                    httpsTransport.AllowCookies = false;
                    httpsTransport.BypassProxyOnLocal = false;
                    httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    httpsTransport.MaxBufferSize = 65536;
                    httpsTransport.MaxBufferPoolSize = 524288;
                    httpsTransport.MaxReceivedMessageSize = 65536;
                    httpsTransport.TransferMode = TransferMode.Buffered;
                    httpsTransport.UseDefaultWebProxy = true;
                    httpsTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
    
                    httpsTransport.ManualAddressing = false;
                    httpsTransport.AllowCookies = false;
                    httpsTransport.BypassProxyOnLocal = false;
                    //httpsTransport.DecompressionEnabled = true;
                    httpsTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    httpsTransport.KeepAliveEnabled = true;
                    httpsTransport.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
                    httpsTransport.Realm = "";
                    httpsTransport.TransferMode = TransferMode.Buffered;
                    httpsTransport.UnsafeConnectionNtlmAuthentication = false;
                    httpsTransport.UseDefaultWebProxy = true;           
    
                    CustomBinding binding1 = new CustomBinding();
                    TextMessageEncodingBindingElement oTextMessageEncod = new TextMessageEncodingBindingElement();
                    oTextMessageEncod.MaxReadPoolSize = 64;
                    oTextMessageEncod.MaxWritePoolSize = 16;
                    oTextMessageEncod.MessageVersion = MessageVersion.Soap12;
                    oTextMessageEncod.WriteEncoding = Encoding.UTF8;
    
                    binding1.Elements.Add(oTextMessageEncod);
                    binding1.Elements.Add(httpsTransport);
    
                    EndpointAddress remoteAddress = new EndpointAddress("https://example.com/Payments/transact2.asmx");
                    
    
                    SmartPayments2SoapClient client = new SmartPayments2SoapClient(binding1, remoteAddress);
                  
                    {
                        client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                    }
    
                    response1 = client.GetInfo("", "", "", "");


    Saturday, February 09, 2013 7:22 AM
  • Hi,

    Thank you very much for you to share your answer to us.

    If you have any other problem, welcome to post it here.

    Best Regards. 


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 12, 2013 11:58 AM
    Moderator