WCF with no app.config
I did a Service Reference in my .NET C# assembly and got the infrastructure for a fully enabled WCF proxy. I also got a app.config file added to my project that I didn’t want. I need to run configuration free since I am running in both COM+ and managed mode (i.e. some public classes are COMVisible and some are Managed), plus my COMVisible classes are hosted in COM+. So I need to get ride of the app.config which looks like this:
<?xml version="1.0" encoding="utf-8" ?><configuration><system.serviceModel><bindings><basicHttpBinding><binding name="AmazonS3SoapBinding" closeTimeout="00:01:00"openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"useDefaultWebProxy="true"><readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"maxBytesPerRead="4096" maxNameTableCharCount="16384" /><security mode="None"><transport clientCredentialType="None" proxyCredentialType="None"realm="" /><message clientCredentialType="UserName" algorithmSuite="Default" /></security></binding></basicHttpBinding></bindings><client><endpoint address="https://s3.amazonaws.com/soap" binding="basicHttpBinding"bindingConfiguration="AmazonS3SoapBinding" contract="AmazonS3.AmazonS3"name="AmazonS3" /></client></system.serviceModel></configuration>
I replaced it with a method like this:
private AmazonS3.AmazonS3 CreateChannel()
{BasicHttpBinding wsHttpBinding = new BasicHttpBinding();
wsHttpBinding.Name = "dynamicBinding";
wsHttpBinding.Security.Mode = BasicHttpSecurityMode.Transport;wsHttpBinding.TextEncoding = Encoding.UTF8;wsHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;wsHttpBinding.AllowCookies = false;
wsHttpBinding.MessageEncoding = WSMessageEncoding.Text;wsHttpBinding.UseDefaultWebProxy = true;
wsHttpBinding.OpenTimeout = new TimeSpan(0, 1, 0);
wsHttpBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
wsHttpBinding.MaxBufferPoolSize = 524288;wsHttpBinding.MaxReceivedMessageSize = 65536;EndpointAddress endpointAddress = new EndpointAddress(AmazonUrl);
ChannelFactory<AmazonS3.AmazonS3> channelFactory = new ChannelFactory<AmazonS3.AmazonS3>(
wsHttpBinding, endpointAddress);return (channelFactory.CreateChannel());
}
I am not a WCF expert, however this code works and not I can delete the app.config.
{6230289B-5BEE-409e-932A-2F01FA407A92}
Comments
Post a Comment