简体   繁体   English

使用WCF服务 - 找不到默认端点元素

[英]Consume WCF Service - Could not find default endpoint element

I followed some guide to consuming WCF service in my windows application. 我按照一些指南在我的Windows应用程序中使用WCF服务。 My WCF Service worked well for my mobile application but I cannot get it working on windows application. 我的WCF服务适用于我的移动应用程序,但我无法在Windows应用程序上运行。

The error generated when i try to run the code is: 我尝试运行代码时生成的错误是:

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

Calling web service method: 调用Web服务方法:

    AllocationService.AllocatingServiceClient client = new AllocationService.AllocatingServiceClient();
    client.notifyZoneChanged(1);

Web Service side: Web服务方面:

    [OperationContract]
    void notifyZoneChanged(int LocationID);

Web Service's web.config: Web服务的web.config:

  <?xml version="1.0"?>
  <configuration>
    <connectionStrings>
      <add name="PCSDB" connectionString="Data Source=alj6d2eqa0.database.windows.net;Initial Catalog=StaffAllocatorDB;Persist Security Info=True;User ID=---;Password=---" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
      <services>
        <service name ="StaffAllocator.AllocatingService">
          <endpoint address="" behaviorConfiguration="AllocationBehavior" binding="webHttpBinding" bindingConfiguration="" contract="StaffAllocator.IAllocatingService">
          </endpoint>
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior>
            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
            <serviceMetadata httpGetEnabled="true"/>
            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
            <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
          <behavior name="AllocationBehavior">
            <webHttp/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

  </configuration>

App.config for windows application: 适用于Windows应用程序的App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="PCSDB" connectionString="Data Source=alj6d2eqa0.database.windows.net;Initial Catalog=StaffAllocatorDB;Persist Security Info=True;User ID=---;Password=---" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AllocationBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <endpoint Name="Default"
              address="http://staffallocatingsystem.cloudapp.net/AllocatingService.svc"
              binding="webHttpBinding"
              behaviorConfiguration="AllocationBehavior"
              contract="AllocationService.IAllocatingService" />
  </system.serviceModel>
</configuration>

Your client side config is missing an <endpoint> node that would define where to connect to - so you need to add this to your config : 您的客户端配置缺少一个<endpoint>节点,该节点将定义连接的位置 - 因此您需要将其添加到您的配置中:

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AllocationBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
       <endpoint Name="Default"
                 address="http://yourserver/virtualweb/YourService.svc"
                 binding="webHttpBinding"
                 behaviorConfiguration="AllocationBehavior"
                 contract="AllocationService.IAllocatingService" />
    </client>
</system.serviceModel>

The address= location is determined by the server name where your server is hosted, the IIS virtual directory where your *.svc file lives, and the name of the *.svc file itself (including the extension) address= location由托管服务器的服务器名称, *.svc文件所在的IIS虚拟目录以及*.svc文件本身的名称(包括扩展名)确定

You need to put the end point 你需要提出终点

<system.serviceModel>
    <client>
       <endpoint Name="Default"
                 address="http://yourserver/virtualweb/YourService.svc"
                 binding="webHttpBinding"
                 behaviorConfiguration="AllocationBehavior"
                 contract="AllocationService.IAllocatingService" />
    </client>
</system.serviceModel>

in the web.config where you need to use it, all the "layers", where the method is used! 在web.config中你需要使用它,所有“层”,使用方法!

Example: if you call it in BLL (logic methods that you craeted) and use it in PL (the web part, HTML). 示例:如果您在BLL中调用它(您使用的逻辑方法)并在PL(Web部件,HTML)中使用它。 In the BLL web.config the end point will be created by default but you gonna need it in the PL web.config that will not be created by default. 在BLL web.config中,默认情况下将创建端点,但您将需要在默认情况下不会创建的PL web.config中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用WCF服务时找不到端点元素 - Could not find endpoint element when consume WCF service 在WCF客户端中找不到默认端点元素… - Could not find default endpoint element … in WCF Client WCF 端点错误:找不到默认端点元素 - WCF Endpoint Error: Could not find default endpoint element 找不到引用合同的默认终结点元素(简单的WCF服务不起作用) - Could not find default endpoint element that references contract (simple WCF Service not working) 找不到引用合同的默认端点元素 - 托管wcf - Could not find default endpoint element that references contract - Hosting wcf 在WCF中找不到引用合同的默认终结点元素 - Could not find default endpoint element that references contract in WCF WCF运行时异常“找不到引用的默认终结点元素……” - WCF Runtime Exception “Could not find default endpoint element that references…” WCF 安装程序 class - 找不到引用合同的默认端点元素 - WCF installer class - Could not find default endpoint element that references contract WCF错误 - 找不到引用合同的默认端点元素 - WCF Error - Could not find default endpoint element that references contract WCF Rest服务引用了另一个由WCF服务托管的应用程序。 找不到默认端点? - WCF Rest service referencing another application hosted WCF Service. Could not find default endpoint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM