[英]Could not find default endpoint element that references contract?
我是WCF service
的初學者。 我創建一個Wcf rest服務。 如果我瀏覽,效果很好。
然后,我添加了一個新的Web應用程序並添加了該服務的引用。 該服務已正確加載。 但是,當我檢查web.config時,它不包含有關服務模型及其空白的任何詳細信息。 我實現並構建並運行了該解決方案,但它中斷並給出此錯誤:
在ServiceModel客戶端配置部分中找不到引用合同'ProductRestService.IProductRESTService'的默認終結點元素。 這可能是因為找不到您的應用程序的配置文件,或者是因為在客戶端元素中找不到與該協定匹配的端點元素。
我的服務webconfig是:
<system.serviceModel>
<services>
<service name="WcfService1.ProductRestService"
behaviorConfiguration="serviceBehavior">
<endpoint address="ProductRestService" binding="webHttpBinding" contract="WcfService1.IProductRESTService"
behaviorConfiguration="web"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
我將其實現為用於測試:
if (!IsPostBack)
{
ProductRestService.ProductRESTServiceClient pro = new ProductRestService.ProductRESTServiceClient("ProductRestService");
var prodcuts = pro.GetProductList();
GridView1.DataSource = prodcuts;
GridView1.DataBind();
}
客戶端web.config為空,原因是:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
</configuration>
我該如何解決此幫助!!!
在您的web.config文件中添加以下代碼,它將解決此問題,
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding_IProductRESTService" />
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://{DomainName}/ProductRestService/" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IProductRESTService" contract="WcfService1.IProductRESTService" name="WebHttpBinding_IProductRESTService" />
</client>
</system.serviceModel>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.