An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll

1

I'm trying to consume a service but gives the error:

  An unhandled exception of type 'System.InvalidOperationException'   occurred in System.ServiceModel.dll

And the message:

  

"Could not find the default endpoint element   which refers to the contract 'ServicoEmpresa.RemoteService' in   configuration section of the ServiceModel client. This may have occurred   due to the lack of a configuration file for your application or   because no endpoint element corresponding to this   contract could be found in the client element. "

Is this a problem in app.config?

Client file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>

    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IEmpresaServicoRemoto" />
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8733/Design_Time_Addresses/PontoCerto.ServicoRemoto/EmpresaServicoRemoto/"
        binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IEmpresaServicoRemoto"
        contract="PontoCerto.ServicoRemoto.Contratos.IEmpresaServicoRemoto" name="BasicHttpBinding_IEmpresaServicoRemoto" />
    </client>
    <behaviors>
    </behaviors>
  </system.serviceModel>
</configuration>"

Arquivo do serviço:
>'<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="CustomMessage" type="PontoCerto.ServicoRemoto.Infraestrutura.CustomBehaviorExtensionElement, PontoCerto.ServicoRemoto,&#xD;&#xA;             Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <services>
      <service name="PontoCerto.ServicoRemoto.Servico.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/PontoCerto.ServicoRemoto/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="PontoCerto.ServicoRemoto.Contratos.IService1">
          <!-- 
              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>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="PontoCerto.ServicoRemoto.Servicos.EmpresaServicoRemoto">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/PontoCerto.ServicoRemoto/EmpresaServicoRemoto/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="wsHttpBinding"
                  contract="PontoCerto.ServicoRemoto.Contratos.IEmpresaServicoRemoto"
                  behaviorConfiguration="ClientEndpointBehavior">
          <!-- 
              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>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientEndpointBehavior">
          <CustomMessage />

        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
    
asked by anonymous 12.03.2015 / 02:08

3 answers

2

In truth this XML is correct, the problem was much more basic, in my architecture I have the project with the screens and another project with the controls, when I referenced the service Visual Studio left the App.config file in the project of control but the correct one and leave the configuration in the project that starts the application.

    
14.03.2015 / 00:46
2

I had exactly Douglas's problem, yet I found another peculiarity. In the AppConfig project that is started, the contract name can not have the full Namespace of it, eg:

Initially I configured as:

<endpoint contract="Core.PCampoBom.Servicos" address="https://nfse.campobom.rs.gov.br/portal/Servicos" binding="basicHttpBinding" bindingConfiguration="ServicosBinding"  name="ServicosPort"/>

But even configuring this in another project, we have to put the internal namespace of the project that uses the webservice:

<endpoint contract="PCampoBom.Servicos" address="https://nfse.campobom.rs.gov.br/portal/Servicos" binding="basicHttpBinding" bindingConfiguration="ServicosBinding"  name="ServicosPort"/>

It's more of a curiosity, I came here more to thank.

    
19.06.2017 / 19:28
0

My case was similar to that of DouglasMendes. To solve, just copy the section system.serviceModel from app.config into the configuration section of web.config of the project that starts the application.

    
22.03.2016 / 14:43