Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception: Could not find default endpoint element when call Bing translate service from RESTFUL service

Tags:

rest

c#

exception

I'm building a RESTFUL webservice and a consoleHost application to host that webservice. In RESTFUL webservice, I call BingTranslate service (link reference to: http://api.microsofttranslator.com/V2/Soap.svc) My service host successfully, but when I call function that call the BingTranslate service, this exception thrown: "Could not find default endpoint element that references contract 'BingTranslator.LanguageService' 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." (BingTranslator is the name of service reference in RESTFUL project)

The app.config of the RESTFUL project is:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_LanguageService" 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>

      <webHttpBinding>
        <binding transferMode="Streamed" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="00:25:00"
                 closeTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00" name="webBinding">
        </binding>
      </webHttpBinding>

    </bindings>
    <client>
      <endpoint address="http://api.microsofttranslator.com/V2/soap.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_LanguageService"
        contract="BingTranslator.LanguageService" name="BasicHttpBinding_LanguageService" />
    </client>
    <services>
      <service name="SearchService.Service1" behaviorConfiguration="SearchService.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/SearchService/Service1/"   />
          </baseAddresses>
        </host>

        <endpoint address=""  binding="webHttpBinding" contract="SearchService.IService1"
                     behaviorConfiguration="Web" bindingConfiguration="webBinding">

          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SearchService.Service1Behavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

and the app.config file of ConsoleHost like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="NewBehavior" name="SearchService.Service1">
        <clear />
        <endpoint address="" binding="webHttpBinding" contract="SearchService.IService1"
            behaviorConfiguration ="Web" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
            contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8787/searchservice" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

"This error can arise if you are calling the service in a class library and calling the class library from another project." -> Perhaps this is my situation. But I don't know how to fix it.

What should I do? Please help me. Thanks a lot. Best Regards

like image 225
Mide Avatar asked Nov 04 '22 08:11

Mide


1 Answers

If you have the service client in a separate class library project, the wcf client configuration (i.e. system.servicemodel section in app.config) is not inherited by the referencing project. You need to copy the System.ServiceModel section of the app.config in the class library project over to the app.config in the exe project.

like image 193
Eren Ersönmez Avatar answered Nov 09 '22 06:11

Eren Ersönmez