【问题标题】:WCF Could not find endpoint element and contractWCF 找不到端点元素和合同
【发布时间】:2018-01-16 10:08:30
【问题描述】:

我正在尝试创建一个 WCF 并从另一个 C# 类中使用它。

我认为我做的一切都是正确的,但我收到错误消息说合同名称不熟悉。

这是我的 Web.config 代码:

<system.serviceModel>
    <services>
      <service behaviorConfiguration="PNMSoft.Sequence.Invoices.InvoicesBehavior" name="PNMSoft.Sequence.Invoices.Invoices">
        <endpoint name="InvoicesEndPoint" address="" binding="wsHttpBinding" contract="PNMSoft.Sequence.Invoices.IInvoices">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PNMSoft.Sequence.Invoices.InvoicesBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
</system.serviceModel>

这是我的界面代码:

namespace PNMSoft.Sequence.Invoices
{
    [ServiceContract]
    public interface IInvoices
    {
        [OperationContract]
        void SendInvoicesToCustomer(int wfid, int userID, int type, string mail, DateTime startDate, DateTime endDate, string clientCode);

    }
}

这是我尝试从服务中激活功能时的代码:

InvoicesClient client = new InvoicesClient("InvoicesEndPoint");
client.SendInvoicesToCustomer(IWFID, userID2, type2, Mail, DateFrom2, DateTo2, clientCode2);

在第一行,我收到以下错误消息:“在 ServiceModel 客户端配置部分中找不到名称为 'InvoicesEndPoint' 和合同 'Invoices.IInvoices' 的端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到匹配此名称的端点元素。”。

这是我这边的配置文件:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="InvoicesEndPoint" />
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="InvoicesEndPoint" contract="Invoices.IInvoices" name="InvoicesEndPoint">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

我想我需要在客户端的配置文件中添加一些内容。我应该添加什么?

提前谢谢你!

【问题讨论】:

  • 您的客户端应用程序中是否有客户端配置?如果不是,那么错误会告诉您缺少什么。如果是,请您将其添加到问题中。你可能是纠正错字InoicesEndPoint
  • 添加服务引用后,客户端应用是否有客户端配置?另外,您在测试时是否同时运行客户端和服务?
  • 你在某处打错字了。 InoicesEndPoint != InvoicesEndPoint.
  • behaviorConfiguration="PNMSoft.Sequence.Invoices.InvoicesBehavior",重命名为其他名称,作为服务行为配置和服务名称同名。

标签: c# wcf wcf-endpoint


【解决方案1】:

我解决了,我只需要将端点添加到客户端的配置中。

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 2013-06-27
    • 2012-01-09
    • 2015-07-01
    • 2014-07-25
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多