【发布时间】:2014-07-02 18:39:05
【问题描述】:
尝试在 C# 中实现 net.tcp WCF 时收到以下错误消息:
“找不到引用合同‘EventInterfaceService.IEventInterface’的默认端点元素 在 ServiceModel 客户端配置部分。这可能是因为没有为您的应用程序找到配置文件, 或者因为在客户端元素中找不到与此合同匹配的端点元素。”
在我的客户端,我有以下代码:
private void Initialize(string sInterfaceUrl, string sUserParticipantName)
{
EventInterfaceCallbackSink _callbackSink;
InstanceContext _instanceContext;
EndpointAddressBuilder _endpointAddressBuilder;
_callbackSink = new EventInterfaceCallbackSink();
_instanceContext = new InstanceContext(_callbackSink);
eventInterfaceClient = new EventInterfaceClient(_instanceContext); //Exception gets thrown here
EndpointIdentity edi = EndpointIdentity.CreateUpnIdentity(sUserParticipantName);
var endpointAddress = eventInterfaceClient.Endpoint.Address;
EndpointAddressBuilder newEndpointAddress = new EndpointAddressBuilder(endpointAddress);
newEndpointAddress.Uri = new Uri(sInterfaceUrl);
newEndpointAddress.Identity = edi;
eventInterfaceClient.Endpoint.Address = newEndpointAddress.ToEndpointAddress();
}
如您所见,我将 EndPointAddress 设为 sInterfaceUrl,将 UserParticipantName 设为 sUserParticipantName。
对于 app.config,我有以下内容:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_Interface" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="Infinite" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
textEncoding="utf-8" useDefaultWebProxy="true" messageEncoding="Text">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IEventInterface"/>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/HTTPWCF/" binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_Interface" contract="InterfaceService.IInterface"
name="basicHttpBinding_Interface" />
<endpoint address="net.tcp://localhost:8733/NETTCPWCF/"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IEventInterface"
contract="EventInterfaceService.IEventInterface" name="NetTcpBinding_IEventInterface">
</endpoint>
</client>
</system.serviceModel>
在独立客户端(不是实际应用程序)中运行此代码时,它可以工作。我似乎无法找出问题所在。任何提示都会很棒!
谢谢。
编辑:有什么方法可以纯粹在运行时配置它,所以我不需要 app.config?关于下面的cmets,可能是找不到配置文件或使用了错误的配置文件。
【问题讨论】:
-
什么是“实际应用”?如果是某个 Web 应用程序,请将 web.config 与此 app.config 进行比较。如果是某个客户端应用程序,请将 someclient.exe.config 与此 app.config 进行比较。
-
听起来您的“实际应用程序”正在读取其他配置?
-
好点。我创建了一个包含类和 app.config 的库项目。我正在一个 ASP.NET 项目中实现这个库的使用。这里会不会有冲突?如果可以,是否可以解决?