Proving that my C# WCF code sees my Web.config file

Shaun Merrill 21 Reputation points
2022-03-16T22:57:01.737+00:00

I am writing code which is targeting the .NET Framework 4. to make a WCF proxy called "CIMClient".

In VS2019 C#, I used Add Service Reference, and imported a wsdl file along with its xsd files.

The wsdl defines an interface named "Operations".

Within the same DLL assembly, here is a section of my C# code:

After defining the request variable,

            using (OperationsClient client = new OperationsClient("SOAP"))
            {
                ResponseMessageType response = client.Request(request);
                return response;
            }

This code above cannot find the following Web.config entry:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="IORRServiceSoapBinding">
                <security mode="Transport">
                    <message clientCredentialType="Certificate"
                            algorithmSuite="Basic192Sha256Rsa15" />
                </security>
            </binding>
            <binding name="SOAP" >
                <security mode="Transport" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
            <endpoint address=" ... "
                        binding="basicHttpBinding"
                        bindingConfiguration="IORRServiceSoapBinding"
                        contract="IIORR"
                        name="IORRPort" />
            <endpoint address=" ... "
                        binding="basicHttpBinding"
                        bindingConfiguration="SOAP"
                        contract="CIMClient.Operations"
                        name="SOAP">
            </endpoint>
        </client>
</system.serviceModel>

I get the following error:

Could not find endpoint element with name 'SOAP' and contract 'CIMClient.Operations' 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.

Can you help me identify whether or not this code can even see my Web.config file?

When I change the code to

 using (OperationsClient client = new OperationsClient())

Then I get an error stating

Could not find default endpoint element that references contract 'CIMClient.Operations' 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.

Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,191 Reputation points Microsoft External Staff
    2022-03-17T03:14:47.893+00:00

    Hi @Shaun Merrill ,
    1.Is CIMClient the namespace you entered when adding the service reference?
    183981-1.jpg
    2."This error can arise if you are calling the service in a class library and calling the class library from another project."
    In this case, you need to copy the configuration settings from the app.config file in the class library referencing the WCF service to the web.config settings of the ASP.NET site/application.
    3.There is a post with the same problem, you can see if his answer can help you.
    https://learn.microsoft.com/en-us/answers/questions/266881/wcf-error-could-not-find-default-endpoint-element.html
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.