sriharsha KB
sriharsha KB

Reputation: 127

Create a WCF Client wihout Configuration File

Kindly help me with this ..

How to create a WCF client without specifying the client config in the app.config.

I have seen this link

.NET - deploying a WCF client, without an app.config

But there, you need to specify the configuration property by property. Is there anyway we can use the app.config configuration as a single string and assign to a class and get it done with?

Like

var config=GetEndpointConfig(endPointName);
var bindingData=GetBinding(nameodBinding);

Where the method returns entire config in string like this.

endpoint:

<endpoint address="http://localhost:61144/Sampler.svc" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_Iervice" contract="IService"
      name="BasicHttpBinding_IService" />

Binding :

<basicHttpBinding>
    <binding name="BasicHttpBinding_IService" 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>

I don't want to import config file and load the configuration in the current application because, there are other modules which will be effected. I am quoting this example which is using

 System.Configuration.Configuration config = 
            System.Configuration.ConfigurationManager.OpenMappedExeConfiguration
            (filemap, 
             System.Configuration.ConfigurationUserLevel.None);

Thanks in Advance!!!

Upvotes: 3

Views: 1121

Answers (2)

tom redfern
tom redfern

Reputation: 31750

Is there anyway we can use the app.config configuration as a single string and assign to a class and get it done with

No.

If the service was created with default values for all the binding parameters you can consume it like this:

using System.ServiceModel;

var factory = new ChannelFactory<IMyServiceInterface>(
    new BasicHttpBinding(), <-- or whatever binding your service uses
    new EndpointAddress("http://MyServiceUrl"));

var proxy = factory.CreateChannel();

Then you can access the service operations via the proxy.

UPDATE

Based on your comments below, take a look at the following link:

Read .NET configuration from database

So no, there is no way to do this nicely (although you can have a look at the Chinchoo framework).

Upvotes: 1

Lior
Lior

Reputation: 171

Yes you can here is an article that loads configuration file you supply for the client side loading configuration file

Upvotes: 1

Related Questions