WCF: Could not find the default endpoint element that references the IService contract in the ServiceModel client configuration section. when hosted on IIS

I have a WCF service that is hosted in IIS. I also have a WCF client (console application). I used svcutil to create a proxy class and configuration file, and then added them to my client project. It is built correctly. But when I tried to run the program, it throws an exception below

Could not find the default endpoint element that references the IService contract in the ServiceModel client configuration section. Perhaps this is due to the fact that the configuration file was not found for your application, or because the leaf element corresponding to this contract was not found in the client element.

// Code of my client program

 namespace MyFirstWCFClient { class Program { static void Main(string[] args) { ServiceClient objClient = new ServiceClient(); Console.WriteLine("Client calling the service...."); string strName=Console.ReadLine(); Console.WriteLine(objClient.HelloWorld("Shyju")); Console.Read(); } } } 

My client's output.config file

  <?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Message"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" /> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://localhost/IISHostedserviceTest/Service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" contract="IService" name="WSHttpBinding_IService"> <identity> <dns value="localhost" /> </identity> </endpoint> </client> </system.serviceModel> </configuration> 

and in web.config my service has the following configuration

  <system.serviceModel> <services> <service name="Service" behaviorConfiguration="ServiceBehavior"> <!-- Service Endpoints --> <endpoint address="http://localhost/IISHostedserviceTest/Service.svc" binding="wsHttpBinding" contract="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="ServiceBehavior"> <!-- 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="false"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> 

I used this ( http://www.wcftutorial.net/WCF-IIS-Hosting.aspx ) to try using WCF.

Can someone help me solve this problem?

+4
source share
4 answers

Quick question: if your client application is called myclient.exe , is your configuration in the same directory as the EXE called MyClient.exe.config ?

You cannot just take output.config from svcutil - you need to either add app.config to your client console project (which will be renamed to MyClient.exe.config when compiling), or you will need to copy / rename output.config to MyClient.exe.config so that your client application can find and use it.

+22
source

You should use a constructor for the client that specifies the endpoint configuration name, for example.

 objClient = new ServiceClient ("WSHttpBinding_IService"); 

This will allow the proxy to use the configuration specified in the configuration file.

+6
source

I had a similar problem with two WCF services that connected to each other.

After generating the output.config + MyService.cs class files using svcutil.exe and copying them to the solution directory, I had the same problem.

Just found the answer to this problem: you need to copy the entire โ€œanchorโ€ tag to the main configuration file inside the โ€œServiceModelโ€ tag and copy your link endpoint located next to the existing endpoints in your main configuration file - which solved the exception problem for me

+3
source

Another approach that you should take is to add a help desk to your hosted IIS. Visual Studio automatically starts svcutil in the background and does the configuration work for you - i.e. Will create an app.config file for you.

Manual execution is good, but I suggest starting it at least once by adding a link to the service to make sure that it works correctly.

+2
source

Source: https://habr.com/ru/post/1300185/


All Articles