class library application not using the app.config file

1k views Asked by At

I am facing problem while consuming the webservice and making an web service call.

I am creating the class library application which will generate the dll and this dll will be used by some other application to connect the webservice.I have received the WSDL file from third part and I "Add a service reference" and used all the proxy classes to create my soap body. Now I have two issues I need to add the wsse:security header to my soap message like below

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
              <wsse:Username>username</wsse:Username>
              <wsse:Password>password</wsse:Password>
            </wsse:UsernameToken>
          </wsse:Security> 

To handle this and to connect the webserivce endpoint address have modified my app.config file (which got generated when add service reference) to include this as header tag. below is my app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ICMS-Http-WSBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results"
          binding="basicHttpBinding" bindingConfiguration="ICMS-Http-WSBinding"
          contract="Ihlth_Service1.ICMSHttpWSPortType" name="ICMS-Http-WSPortType">
        <headers>
          <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:UsernameToken>
              <wsse:Username>username</wsse:Username>
              <wsse:Password>password</wsse:Password>
            </wsse:UsernameToken>
          </wsse:Security>
        </headers>
      </endpoint >
    </client>
  </system.serviceModel>
</configuration>

When I tried to initialize my client as below I am facing the error as Could not find endpoint element with name 'ICMS-Http-WSPortType' and contract 'Ihlth_Service.ICMSHttpWSPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element

Service.CMSHttpWSPortTypeClient Client = new Service.CMSHttpWSPortTypeClient("ICMS-Http-WSPortType");  

I modified my code to create a binding and endpoint address inside the code and pass to the client then it worked fine but again faced issue at the security header missing as I provided the security information in app.config file

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
 EndpointAddress address = new EndpointAddress("https://devs-dp-in.wellpoint.com/Claims/2.0/Get_iHealthICMS_Results");

is there any way that I can read the app.config file or my code refer that config file to get the information rather giving inside the code.

This entire code is working fine in the windows application by reading the app.config file but not in the class library application is there any reason behind that ?

Any one please give some idea

1

There are 1 answers

3
Damien_The_Unbeliever On

The app.config of a DLL is, at best, a reminder of what needs to be placed in the app.config of the EXE that consumes your DLL or the web.config of a website that consumes your DLL.

It's not actually used by default by the configuration system, and it's slightly unfortunate that some tooling (such as Add Service Reference) will create one in a class library project and give no warning about this.