0

our software uses many WebService calls via

sc = new MyServiceSoapClient() 

and this contructor reads EndpointAddress and Binding and Behavior from Winword.exe.config (this is because out software is a winword Addin)

But the customer demands that we dont touch the Winword.exe.config file.

So we changed our strategy to create a channel from a ChannelFactory because in this case we can use any ".config" file we like.

unfortunatedly the channel we get from the ChannelFactory is a "MyServiceSoap" but it is not a "MyServiceSoapClient".

We dont want to do each WebService call via the created channel because this would imply that we re-implemented very many calls like this:

creating a request object

calling the WebService Method

reading the result from the response object.

so we tried to instanciate the MyServiceSoapClient this way:

sc = new MyServiceSoapClient(chfact.Endpoint.Binding, chfact.Endpoint.Address)

this worked fine, we finally got our SoapClient out of any ".config" file and we were not depending on the Winword.exe.config file.

but then the customer added some Behavior to the config file because of security reasons.

well, the channelFactory certainly reads the Behavior from the config file but there is no constructor like this:

sc = new MyServiceSoapClient(Binding, Address, Behavior)

so we cannot create a FULLY VALID MyServiceSoapClient from an existing MyServiceSoap-channel.

The Behavior works fine if we created the MyServiceSoapClient with it's default constructor - but then the customer would need to configure the Winword.exe.config what he denies to do.

It is also impossible to typecast like this:

sc=(MyServiceSoapClient)channel;

because channel is a MyServiceSoap interface.

QUESTION:

Is there any way to create a MyServiceSoapClient from a MyServiceSoap-channel or from a channelFactory ?

Or can it be done with some sophisticated Type-Casting?

many thanks in advance

yours, Gerald

Gerald Trost
  • 199
  • 11

1 Answers1

0

What if you put all the wcf config in external files so you wouldn't need to touch winword.exe.config ever again:

<system.serviceModel>
   <bindings configSource="bindings.config" />
   <behaviors configSource="behaviors.config" />
   <client configSource="client.config" />
   <services configSource="services.config" />
  .....
</system.serviceModel>

So for each section inside <system.serviceModel>, you could specify an external config file by using the configSource= attribute (and don't let Visual Studio's red squiggly lines confuse it - yes, it DOES work!).

You can do this for any configuration section - but unfortunately, there's no way to do this for the whole section group (<system.serviceModel>).

(this was copied from this answer: https://stackoverflow.com/a/1598776/725866)

Community
  • 1
  • 1
Jeremy Danyow
  • 26,470
  • 12
  • 87
  • 133
  • oops - soory, I was not clear enough. actually the customer does not want to have any Winword.exe.config file at all. – Gerald Trost Mar 27 '14 at 21:44