2012-01-09 73 views
5

我正在构建一个RESTful的webservice和一个consoleHost应用程序来承载该webservice。 在RESTFUL webservice中,我调用了BingTranslate服务(链接引用为:http://api.microsofttranslator.com/V2/Soap.svc) 我的服务主机成功完成,但是当我调用调用BingTranslate服务的函数时,引发以下异常: “找不到引用合同的默认端点元素BingTranslator .LanguageService“在ServiceModel客户端配置部分中,这可能是因为没有为您的应用程序找到配置文件,或者是因为在客户端元素中找不到匹配此合同的端点元素。 (Bing翻译是REST风格的项目服务引用名称)例外:找不到默认的端点元素,当从RESTFUL服务调用Bing翻译服务

REST风格的项目的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> 

和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> 

“如果您正在调用类库中的服务并从另一个项目调用类库,则会出现此错误。” - >也许这是我的情况。但我不知道如何解决它。

我该怎么办? 请帮帮我。非常感谢。 问候

回答

2

如果你有一个单独的类库项目服务客户端,WCF客户端配置(即system.servicemodel中的app.config部分)不被引用的项目继承。您需要将类库项目中的app.config的System.ServiceModel部分复制到exe项目中的app.config。

+0

我已经完成了。非常感谢。 Yeath! – Mide 2012-01-09 13:55:20

+0

Hi..can你可以发送它的代码。 – user3217843 2014-05-27 09:25:28