3

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!!!

Community
  • 1
  • 1
sriharsha KB
  • 127
  • 1
  • 11
  • possible duplicate of [.NET - deploying a WCF client, without an app.config](http://stackoverflow.com/questions/7688798/net-deploying-a-wcf-client-without-an-app-config) – tom redfern Jan 31 '14 at 16:04

2 Answers2

1

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).

Community
  • 1
  • 1
tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • When I said get all configuration in single string, I meant only endpoint configuration in a string not the entire config file. I have worked in a project which saved these parts of configs like end point and binding in different tables and could get them on the run and create a client. I could not get that code now .... – sriharsha KB Feb 04 '14 at 11:31
  • Thanks for the update @hugh However, I can only get the configuration point from the XML and create a config object from it using that method. Still, how to create a wcf proxy from it is not mentioned. – sriharsha KB Feb 06 '14 at 06:27
  • @sriharshaKB why do you want to do this anyway? – tom redfern Feb 06 '14 at 08:02
  • The reason we did it in our previous project is, if we can change the WCF server, we can do it without restarting the web application.(as config change restarts website). Second, we don't get permission to touch app.config here. We can add/change data in DB on the other hand. And I know that we can do it... It was done in our previous proj.. I just did not know how they did it... – sriharsha KB Feb 06 '14 at 14:43
  • "Second, we don't get permission to touch app.config here". So you are saying you are not allowed to make changes to the one thing which you are supposed to make changes to in the application? I would resign. – tom redfern Feb 10 '14 at 13:35
1

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

Lior
  • 171
  • 2
  • 11
  • In this also the configuration has to be loaded from a file... and that will be applied to the current loaded application. I want to get endpoint configuration separately from DB and create a client. Any way? – sriharsha KB Feb 04 '14 at 11:32