locked
"Could not find default endpoint element that references contract" error; .Config in separate project RRS feed

  • Question

  • I have a .NET project with a web client and a separate .dll for some business logic.  If I add a WCF service reference to the web client, the calls to the WCF service work just fine.

     

    However, if I add the WCF reference to the separate .dll project and not the web client and try to instantiate the service I get the following error:

     

    "Could not find default endpoint element that references contract 'MyService.IServiceTest' 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 contract could be found in the client element."

     

    Now in my case I know it is directly associated with the WCF settings in the .config file.  When adding to the web client project, the settings are added to the web.config file and everything works fine.  When I add the reference to the separate .dll project, the settings get added to the app.config file and calls to it do not work.

     

    The problem I believe is that the app at runtime can not find those settings in the app.config file.  Even when I set the app.config file properties to 'Copy Always' for the 'Copy to Output Directory' setting, it still does not work.  I even tried renaming the app.config to MyDllName.dll.config and that did not work either.

     

    I am sure others have solved this before, so can anyone let me know how to make this work?

     

    Thanks!

    Wednesday, June 18, 2008 7:36 PM

Answers

  • Hi again,

     Yes, I'm afraid this is so - so you have to administrate your main configuration yourself.
     For client configurations, svcutil.exe has the ability to merge in the generated configuration block (into a given app.config),
     this way you can have a template app.config with all the "others" and then you will merge in the client's configuration block into it.

     --larsw
    Wednesday, June 18, 2008 8:08 PM

All replies

  • Hi,

     Can you try to copy the relevant section from the app.config to your executable's app.config (and not the library) ?

     --larsw
    Wednesday, June 18, 2008 7:52 PM
  • Yes, that works.  However, if I ever refresh my WCF reference in the .dll, I must always remember to copy everything in the <system.serviceModel> from the .dll .config back to the web client web.config.

     

    I was trying to prevent this.  Is this the intended solution by Microsoft when using multiple projects and WCF?

    Wednesday, June 18, 2008 8:04 PM
  • Hi again,

     Yes, I'm afraid this is so - so you have to administrate your main configuration yourself.
     For client configurations, svcutil.exe has the ability to merge in the generated configuration block (into a given app.config),
     this way you can have a template app.config with all the "others" and then you will merge in the client's configuration block into it.

     --larsw
    Wednesday, June 18, 2008 8:08 PM
  • I too am having this error.  I am trying to expose a WCF webservice via a Factory object.

    Can you lend some clarification as to what I should be looking for.

    here is my app.config file from the factory class.
    the factory lives in the namespace MA.BroadcastPeriods.Factory

    <system.serviceModel>
            <bindings>
       <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>
      </bindings>
      <client>
       <endpoint address="http://localhost:2225/Service.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService" contract="WCFService.IService"
        name="BasicHttpBinding_IService" />
      </client>
      <services>
                <service name="WCFService.Service" behaviorConfiguration="WCFService.Service1Behavior">
                    <!-- Service Endpoints -->
                    <endpoint address="" binding="basicHttpBinding" contract="WCFService.IService">
                        <!--
                  Upon deployment, the following identity element should be removed or replaced to reflect the
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
                  automatically.
              -->
                        <identity>
                            <dns value="localhost"/>
                        </identity>
                    </endpoint>
                    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
                </service>
            </services>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="WCFService.Service1Behavior">
                        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                        <serviceMetadata httpGetEnabled="true"/>
                        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                        <serviceDebug includeExceptionDetailInFaults="true"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
        </system.serviceModel>
    </configuration>

    The Service model section from my web.config file is as follows.

    <system.serviceModel>
        <services>
          <service name="WCFService.Service" behaviorConfiguration="WCFService.Service1Behavior">
            <!-- Service Endpoints -->
            <endpoint address="" binding="basicHttpBinding" contract="WCFService.IService">
              <!--
                  Upon deployment, the following identity element should be removed or replaced to reflect the
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
                  automatically.
              -->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="WCFService.Service1Behavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    It seems as if all the endpoints are copecetic.  Any assistance you can provide would be greatly appreciated.

    Thanks.
    Friday, June 27, 2008 1:31 AM
  • Make sure you copy the entire <system.serviceModel> section to your .config file of your main (possibly UI portion of the application) .config file.

     

    So in my case, I was consuming the WCF servie in the Business Layer, so the <system.serviceModel> settings were placed in the app.config for the BLL .dll.  In order for me to prevent the error, I had to copy all of these settings from the app.config, and paste them into my web.config.  The main application is going to look to its .config file for the WCF settings, not anywgere else apparently.  If you figure out how to tell WCF to look for its settings in another .config, please let us know, but according to a previous post it sounds like that is by design.

     

    Friday, June 27, 2008 1:22 PM
  • That didn't work.

     

    Now I have the exact same <system.servicemodel> definition in both my web.config on the WCF service and in the app.config file for my factory object, and am still getting the same error.

    Friday, June 27, 2008 2:49 PM
  • OK - so what if I don't have a .NET EXE at all?

    I am developing an Outlook Add In (A DLL) that references a BLL DLL which in itself uses WCF. Whenever I try to instantiate the endpoint I get errors because the configuration can not be read. I understand the solutions presented above but I have no .NET Exe with a config file so where do I put the settings?

     

     

    Wednesday, July 9, 2008 3:25 PM
  •  

    Hi,

     

     Create an Outlook.exe.config in C:\Program Files\Microsoft Office\Office12 (if you are using office 2007)

     and put the WCF configuration there.

     

     --larsw

    Wednesday, July 9, 2008 4:17 PM
  • Hi atconway

    In this case you need to do something  Programmatically, you need provide Binding and EndingPointAddress to class constructor 

    Binding binding = new WSHttpBinding();
    EndpointAddress endpointAddress = new EndpointAddress("http://localhost/MyService.svc?wsdl");
                
    MyService1Client  mysClient =  new MyService1Client(binding, endpointAddress);
    mysClient.Test();

    Try this, I think this may be help you.

    Thanks

    • Proposed as answer by AtulKatare Friday, December 5, 2008 11:14 AM
    Friday, December 5, 2008 11:14 AM
  • I got the solution by doing the following thing:

    When one has a .dll project and is referencing the service, the app.config file's entire configuration should go into the .exe's config file  which would be running this .dll project.

    - Sachin Doshi 
    • Proposed as answer by SachinDoshi Monday, January 12, 2009 9:37 AM
    Monday, January 12, 2009 9:37 AM
  •  Sachin -

    I believe you are stating the same thing I did earlier in this thread: the WCF configuration generated in the .dll's config has to be manually copied up to the main projects (most likely UI layer) .config file.  I believe this is needed because the WCF service will look for its configuration data in the context from which it is being called.  I come to this conclusion from developing WCF with Silverlight and some of the limitations in making WCF calls while debugging with a web site.  If I am incorrect in this assumption, please anybody speak up.

    The main problem with this solution is that everytime the WCF service is refreashed, it will not re-copy that new configuration data to your main project's .config file.  Therefore, it is important to remember to re-copy the configuration data each time the WCF service is consumed.

    Another alternative was offered up is using the 'Merge' capabilities of the svcutil proxy generation tool, but I do not use that as I consume my services via the "Add Service Reference" link in Visual Studio.  If anybody knows about the "Merge" capability within VS.NET please also feel free to speak up.
    Tuesday, March 10, 2009 7:01 PM
  • I met the same error when I start to learn WCF today.

    How did I solve it:

    Copy all things from "output.config" to "app.config" under <Configuration>. Then it works.

    I compare the code and found the only different is under <Client>:

    <

     

    client>

    <

     

    endpoint address="http://localhost:1247/Server.Wcf.Service/Service.svc"

     

     

    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"

     

     

    contract="ServiceReference1.IService" name="BasicHttpBinding_IService" />

    </

     

    client>


    The succeed one remove ServiceReference1.

    I don't know why now - -..... I think I need know more about WCF.
    Friday, September 4, 2009 6:54 AM
  • Thanks a lot atconway ....

    i had the same scenario and your solution solved my problem.
    Thursday, September 10, 2009 11:16 AM
  • hi All,

    I just started working on WCF...and facing same problem

    I am trying to develop an 3 tier architecture, which have following layers

    1) Web Layer
    2) Web Services proxy
    3) Web services
    4) Business Layer
    5) Business Service Proxy
    6) Business Service
    7) Data Access Layer.

    now I tried by creating .svc services for my Business Service layer, and this is where I am getting this error.

    As mentioned by @atconway I tried to copy <system.servicemodel> node generated in Business Service Proxy layer into
    First Web Layer web config....and then even tried by copying it in Web service Web config.....

    but No Luck......

    I can't believe that user has to maintain config file himself in case of multiple layer.
    If anyone facing same problem, and has any suggestion or solution. Please share.

    Regards,
    Pankaj
    Thursday, September 10, 2009 12:08 PM
  • Hi atconway

    In this case you need to do something  Programmatically, you need provide Binding and EndingPointAddress to class constructor 

    Binding binding = new WSHttpBinding();
    EndpointAddress endpointAddress = new EndpointAddress("http://localhost/MyService.svc?wsdl");
                
    MyService1Client  mysClient =  new MyService1Client(binding, endpointAddress);
    mysClient.Test();

    Try this, I think this may be help you.

    Thanks


    Thanks a lot.
    I solved my problem using above code.
    I was unable to call WCF Wervice using class library.
    But now its working.
    Monday, October 5, 2009 3:53 PM
  • Hi Pankaj.
    I was wondering If you has solved your problem? In fact, I got exactly the same type of solution, and the same problem.
    If I switch the web layer (Silverlight in my case) to a winform, but do the same call from there, It works just fine. It's the service layer between business and data that failes for me.

    Regards,
    Erik
    ejo
    Thursday, November 26, 2009 4:24 PM
  • Hi all,

    I'm also faced with this problem. My situation is as follows:
    - DLL which read its own config file (by using configurationManager.openExeConfiguration(dllname.dll.config))
    - main application which uses the DLL (3d-party application, written in Progress)

    This is working fine, the dll reads the right configsettings.

    Now I must add a service-reference to my DLL. The problem is that it tries to read the standard app.config file (which doesn't exist), instead of reading the dllname.dll.config file.

    Anyone has a solution for this?

    Thanks,


    Tuesday, January 5, 2010 11:14 AM
  • To read config file from different loaction : http://www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location.aspx http://blogs.msdn.com/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx
    Best Regards, Uday Kadam
    Thursday, March 25, 2010 1:53 PM
  • To read config file from different loaction :

    http://www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location.aspx


    http://blogs.msdn.com/dotnetinterop/archive/2008/09/22/custom-service-con
    Best Regards, Uday Kadam
    Thursday, March 25, 2010 1:54 PM
  • Thanks a lot Lars. Your solution worked in my scenario.
    Nikunj Naik
    Monday, July 19, 2010 9:35 PM
  • When using the svcutil.exe to generate the .cs class, do what TangYao suggests:

    Copy all things from "output.config" to "app.config" under <Configuration>.

    Wednesday, January 12, 2011 8:43 PM
  • Hi,

     Can you try to copy the relevant section from the app.config to your executable's app.config (and not the library) ?

     --larsw


    Hi Lars,

     

    Can you please elaborate more on the relevent section?


    Ram
    Friday, January 28, 2011 2:33 PM
  • Hi atconway
    In this case you need to do something  Programmatically, you need provide Binding and EndingPointAddress to class constructor 
    Binding binding = new WSHttpBinding();
    EndpointAddress endpointAddress = new EndpointAddress("http://localhost/MyService.svc?wsdl");
                
    MyService1Client  mysClient =  new MyService1Client(binding, endpointAddress);
    mysClient.Test();
    Try this, I think this may be help you.
    Thanks

    Good looking out! This worked for me. I am calling a asmx service through the InteropControl Toolkit so I couldn't figure out what to name the .config file anyhow. The myinterop.dll.config wasn't being found, and creating a myapplication.exe.config for the VB6 client didn't work either (though it did with a .NET client). I ended up going with:

     

     Dim binding As New BasicHttpBinding
     Dim endpointAddress As New EndpointAddress("http://yourwebsite.com/ws/yourclientservice.asmx?wsdl")
     myWMSClient = New WMSClient.WMSClientServiceSoapClient(binding, endpointAddress)
    Worked like a charm.


    God help me I am trying to work in VB.NET 2005
    Tuesday, August 9, 2011 4:47 PM
  • I ran into this error today ... this thread gave me a hint on how to resolve.

    In my case the solution was to simply ADD the Web Service reference to my calling application as any included DLL (class libraries) that reference the same service apparently MUST also be defined in the calling application ... bizarre I know and clearly a bug in VS 2010 and VS 2008 that hasn't been addressed.

    My Solution/Project is a Silverlight 4 Application with a Web Application/Site using WCF silverlight enabled web services.  Basically looks like:

    MyApp.Web

    --- Service1.svc

    --- MyApp.ASPX stub for calling the Silverlight .XAP

    MySLApp

    --- Project reference to MySLClassLibrary

    --- Project reference to Service1.svc  (REQUIRED even if not used directly in the project)

    --- MyAppUI.xaml.vb creates instantce of MyClass1

    MySLClassLibrary

    --- Project reference to Service1.svc

    --- MyClass1.vb

    Hope this helps ... as usual, the error message provided by Microsoft is almost meaningless ... maybe one of these days we'll actually get some helpful error messages from Microsoft -- I can't dream can't I? ;)

    Rob.

     


    "For me, it is far better to grasp the Universe as it really is than to persist in delusion, however satisfying and reassuring." - Carl Sagan
    Friday, September 2, 2011 2:34 PM
  • This Worked fine for Me..Thanks for the Valuable Post ))
    Thursday, August 2, 2012 1:29 PM
  • Thanks Shyam,

    worked like a charm, once I switched WSHttpBinding for BasicHttpBinding (since otherwise I got: "Content Type application/soap+xml; charset=utf-8 was not supported by service").

    Reg.
    Rene

    Monday, April 6, 2015 1:59 PM
  • can you send web.config sample code
    Tuesday, April 7, 2015 5:44 PM