[英]C# WCF - net.tcp cannot find endpoint
尝试在C#中实现net.tcp WCF时收到以下错误消息:
“在ServiceModel客户端配置部分中找不到引用合同'EventInterfaceService.IEventInterface'的默认端点元素。这可能是因为找不到应用程序的配置文件,或者是因为在客户端元素中找不到与该合同匹配的端点元素“。
在我的客户端上,我有以下代码:
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? 关于以下注释,可能找不到配置文件或使用了错误的配置文件。
您的评论提到您正在将app.config内容放入类库中。 这将不会被读取。 而是读取执行程序集的app.config(或web.config,因为它是ASP)。 您将需要将相关的配置信息添加到执行程序集的配置文件中(您的ASP项目)。
另外,您可以使用静态ConfigurationManager类读取特定的app.config设置: http : //msdn.microsoft.com/zh-cn/library/system.configuration.configurationmanager.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.