我试图创建一个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);
在第一行,我收到以下错误消息:&#34;找不到名称为&#39; InvoicesEndPoint&#39;的端点元素和合同&#39; Invoices.IInvoices&#39;在ServiceModel客户端配置部分中。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素。&#34;。
这是我方客户的配置文件:
<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>
我想我需要在客户端的配置文件中添加一些东西。我应该添加什么?
提前谢谢!
答案 0 :(得分:0)
我解决了它,我只需要将端点添加到客户端的配置。