找不到引用契约的默认端点元素

本文关键字:端点 元素 默认 引用 契约 找不到 | 更新日期: 2023-09-27 18:14:24

我是WCF service的初学者。我创建了一个Wcf rest服务。这工作很好,如果我浏览它。

然后我添加了一个新的web应用程序并添加了该服务的引用。服务被正确加载。但是当我上网的时候。配置它不包含任何关于服务模型的细节,它为空。我实现并构建并运行解决方案,它中断并给出此错误:

找不到引用契约的默认端点元素"ProductRestService。在ServiceModel客户端中的IProductRESTService配置部分。这可能是因为没有配置文件为您的应用程序找到,或者因为没有端点元素匹配此合同可以在client元素中找到。

我的服务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。配置为空:

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" />
    </system.web>
</configuration>

我如何解决这个帮助!!

找不到引用契约的默认端点元素

在您的网页中添加以下代码。配置文件,它会解决问题,

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