Call HTTPS wcf service using programmatically created binding

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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.....

View the full article
 
Back
Top