简体   繁体   English

找不到引用合同的默认端点元素?

[英]Could not find default endpoint element that references contract?

I am a beginner to WCF service . 我是WCF service的初学者。 I create a Wcf rest service. 我创建一个Wcf rest服务。 This works fine if i browse it. 如果我浏览,效果很好。

Then i added a new web application and add reference of that service. 然后,我添加了一个新的Web应用程序并添加了该服务的引用。 The service is loaded correctly. 该服务已正确加载。 But when I check the web.config it doesnot contain any detail about service model and its empty. 但是,当我检查web.config时,它不包含有关服务模型及其空白的任何详细信息。 I implemented and built and run the solution, it breaks and give this error: 我实现并构建并运行了该解决方案,但它中断并给出此错误:

Could not find default endpoint element that references contract 'ProductRestService.IProductRESTService' in the ServiceModel client configuration section. 在ServiceModel客户端配置部分中找不到引用合同'ProductRestService.IProductRESTService'的默认终结点元素。 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. 这可能是因为找不到您的应用程序的配置文件,或者是因为在客户端元素中找不到与该协定匹配的端点元素。

My service webconfig is as: 我的服务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>

and I implemeted it for testing as: 我将其实现为用于测试:

 if (!IsPostBack)
  {
       ProductRestService.ProductRESTServiceClient pro = new ProductRestService.ProductRESTServiceClient("ProductRestService");
       var prodcuts = pro.GetProductList();
       GridView1.DataSource = prodcuts;
       GridView1.DataBind();
  }

and client web.config is empty as: 客户端web.config为空,原因是:

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

</configuration>

How do I resolve this help!!! 我该如何解决此帮助!!!

Add Following code in your web.config file and it will fix the problem, 在您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM