[英]Exception: Could not find default endpoint element when call Bing translate service from RESTFUL service
我正在構建一個RESTFUL Web服務和一個consoleHost應用程序來托管該Web服務。 在RESTFUL webservice中,我調用BingTranslate服務(鏈接參考: http ://api.microsofttranslator.com/V2/Soap.svc)我的服務主機成功,但當我調用調用BingTranslate服務的函數時,拋出此異常:無法找到引用ServiceModel客戶端配置部分中的合同“BingTranslator.LanguageService”的默認端點元素。這可能是因為找不到您的應用程序的配置文件,或者因為在客戶端元素中找不到與此合同匹配的端點元素。 “ (BingTranslator是RESTFUL項目中服務引用的名稱)
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>
和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>
“如果您在類庫中調用服務並從另一個項目調用類庫,則會出現此錯誤。” - >也許這就是我的情況。 但我不知道如何解決它。
我該怎么辦? 請幫我。 非常感謝。 最好的祝福
如果在單獨的類庫項目中具有服務客戶端,則引用項目不會繼承wcf客戶端配置(即app.config中的system.servicemodel部分)。 您需要將類庫項目中app.config的System.ServiceModel部分復制到exe項目中的app.config。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.