简体   繁体   English

例外:从RESTFUL服务调用Bing翻译服务时找不到默认端点元素

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

I'm building a RESTFUL webservice and a consoleHost application to host that webservice. 我正在构建一个RESTFUL Web服务和一个consoleHost应用程序来托管该Web服务。 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." 在RESTFUL webservice中,我调用BingTranslate服务(链接参考: http ://api.microsofttranslator.com/V2/Soap.svc)我的服务主机成功,但当我调用调用BingTranslate服务的函数时,抛出此异常:无法找到引用ServiceModel客户端配置部分中的合同“BingTranslator.LanguageService”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。 “ (BingTranslator is the name of service reference in RESTFUL project) (BingTranslator是RESTFUL项目中服务引用的名称)

The app.config of the RESTFUL project is: RESTFUL项目的app.config是:

<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: 和ConsoleHost的app.config文件是这样的:

<?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 最好的祝福

If you have the service client in a separate class library project, the wcf client configuration (ie system.servicemodel section in app.config) is not inherited by the referencing project. 如果在单独的类库项目中具有服务客户端,则引用项目不会继承wcf客户端配置(即app.config中的system.servicemodel部分)。 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. 您需要将类库项目中app.config的System.ServiceModel部分复制到exe项目中的app.config。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用WCF服务 - 找不到默认端点元素 - Consume WCF Service - Could not find default endpoint element 使用服务时出错:“找不到引用合同的默认端点元素” - Error when using service: “Could not find default endpoint element that references contract” 使用WCF服务时找不到端点元素 - Could not find endpoint element when consume WCF service 找不到引用合同的默认终结点元素(简单的WCF服务不起作用) - Could not find default endpoint element that references contract (simple WCF Service not working) WCF运行时异常“找不到引用的默认终结点元素……” - WCF Runtime Exception “Could not find default endpoint element that references…” 当被其他类库访问时,类库中消耗的WCF服务给出“找不到端点元素……”错误 - WCF Service consumed in Class Library, when accessed by other Class Library gives “Could not find endpoint element…” Error WCF Rest服务引用了另一个由WCF服务托管的应用程序。 找不到默认端点? - WCF Rest service referencing another application hosted WCF Service. Could not find default endpoint? 在WCF客户端中找不到默认端点元素… - Could not find default endpoint element … in WCF Client 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract 找不到引用合同的默认端点元素 - Could not find default endpoint element that references contract
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM