An unhandled Exception of type 'System.Invalidoperationexception' occurred in System.ServiceModel.dll

Asked

Viewed 6,139 times

1

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

An unhandled Exception of type 'System.Invalidoperationexception' occurred in System.ServiceModel.dll

And the message:

"Could not locate standard endpoint element which refers to the contract 'Servicoempresa.Iempresaservicoremoto' on Client Servicemodel configuration section. 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 customer element."

This and problem in the 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>
  • Probably yes, has how to post the app.config?

  • @Douglasmendes, I believe your service had an Endpoint Basichttpbinding and you changed it to Wshttpbinding. If so, try removing the Service Reference and adding it again.

  • @Tobymosque I made this change in trying to solve the problem, really the initial project was Basichttpbinding. The funny thing is that using Wcftestclient works normally, but when I try to instantiate the error service this error in the "proxy" class in the client.

  • Adding as Service Reference? The Service is a WCF application or a WCF library?

  • And as a Service Reference and is a WCF library

3 answers

3

I had exactly the problem of Douglas, yet I found another peculiarity. In the Appconfig of the project that is started, the contract name cannot have the full Namespace of it, example:

Initially set up as:

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

But even setting this up 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 in here to thank.

  • Okay, Douglas' answer is correct, can he get his vote in favor? Because this information has been useful to me, and I want it to remain relevant to future users who encounter this problem. .

  • @felipeAS you can mark the question as favorite, it is visible to you in your profile

2

Actually 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 control project but the correct one and leave the configuration in the project that starts the application.

0

My case was similar to Douglasmendes. To solve, I just copied the section system.serviceModel of app.config into the section configuration of web.config of the project initiating the.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.