Class library application not using app.config file

I am facing a problem when using a web service and calling the web service.

I am creating a class library application that will generate a dll and this DLL will be used by some other application to connect the webservice. I got the WSDL file from the third part and I "Add Service Reference" and used all the proxy classes to create my soap body. Now I have two problems, 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 deal with this and bind the webserivce endpoint address, I modified my app.config file (which got generated when adding a service link) to include this as a title 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 shown below, I ran into an error because I could not find an endpoint element named "ICMS-Http-WSPortType" and contract "Ihlth_Service.ICMSHttpWSPortType" in the client configuration section of ServiceModel. This may be because the config file was not found for your application or because the end element matching that name was not found in the client element

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

      

I changed my code to create the bind and endpoint address inside the code and pass it to the client, then it worked fine, but ran into the problem again in the security header as I provided the security information in the 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 a way that i can read the app.config file, or my code is referencing this config file to get the information instead of giving inside the code.

All this code works fine in a windows application reading the app.config file, but not in a class library application, is there any reason for this?

Anyone please give some insight

+3


source to share


1 answer


app.config

A DLL is, at best, a reminder to put in the app.config

EXE that consumes your DLL or web.config

a website that consumes your DLL.



It is not actually used by default by the config system, and it is a bit unfortunate that some tools (for example Add Service Reference

) will create it in a class library project and not warn about it.

+2


source







All Articles