WCF Discovery .NET 4:配置/以编程方式定义的问题
我有一个启用发现的 WCF 服务,现在我想将客户端连接到它。
问题:当我使用 udp 端点(1.)并尝试以编程方式发现服务时,它可以工作...当我使用 App.config 方法(2.)时,它不能(错误:未发现端点)。
在我看来,这两个解决方案的“udp 发现结果”应该是相同的,但不幸的是它不是......
1。以编程方式(有效):
代码:
DiscoveryClient discClient = new DiscoveryClient("udpDiscoveryEndpoint");
FindCriteria fCriteria = new FindCriteria(typeof(IAlarmServer));
fCriteria.Duration = TimeSpan.FromSeconds(5);
fCriteria.MaxResults = 1;
FindResponse fResponse = discClient.Find(fCriteria);
EndpointAddress address = fResponse.Endpoints[0].Address;
Console.WriteLine("Address found: " + address.ToString());
配置:
<system.serviceModel>
<client>
<endpoint name="udpDiscoveryEndpoint" kind="udpDiscoveryEndpoint" />
</client>
</system.serviceModel>
2。使用 App.config 和“集成到端点”方法的方法(不起作用!):
代码:
var Proxy = new AlarmServerClient("IAlarmServer"); // Default client generated by Visual Studio
Proxy.SomeMethod(); // throw no endpoints discovered exception
配置:
<standardEndpoints>
<dynamicEndpoint>
<standardEndpoint name="discoveryDynamicEndpointConfiguration">
<discoveryClientSettings>
<findCriteria duration="00:00:05" maxResults="1">
<types>
<add name="AlarmServiceRef.IAlarmServer"/>
</types>
</findCriteria>
<endpoint kind="udpDiscoveryEndpoint"/>
</discoveryClientSettings>
</standardEndpoint>
</dynamicEndpoint>
</standardEndpoints>
配置:
<client>
<endpoint binding="basicHttpBinding" bindingConfiguration="DefaultBasicHttpBinding" contract="AlarmServiceRef.IAlarmServer" name="IAlarmServer"
kind="dynamicEndpoint"
endpointConfiguration="discoveryDynamicEndpointConfiguration"/>
</client>
有什么想法为什么会发生这种情况吗?
i have a discovery enabled WCF service and now i want to connect the client to it.
Problem: When i use the udp endpoint ( 1. ) and try to programmatically discover the service, it works... When i use the App.config approach ( 2. ) it does not ( Error: No endpoints discovered ).
To me it seems the "udp discovery result" of both of the solutions should be the same, but unfortunately it isn't...
1. Programmatically approach (works ):
Code:
DiscoveryClient discClient = new DiscoveryClient("udpDiscoveryEndpoint");
FindCriteria fCriteria = new FindCriteria(typeof(IAlarmServer));
fCriteria.Duration = TimeSpan.FromSeconds(5);
fCriteria.MaxResults = 1;
FindResponse fResponse = discClient.Find(fCriteria);
EndpointAddress address = fResponse.Endpoints[0].Address;
Console.WriteLine("Address found: " + address.ToString());
Config:
<system.serviceModel>
<client>
<endpoint name="udpDiscoveryEndpoint" kind="udpDiscoveryEndpoint" />
</client>
</system.serviceModel>
2. Approach with App.config and "integrated into endpoint" approach (does not work!):
Code:
var Proxy = new AlarmServerClient("IAlarmServer"); // Default client generated by Visual Studio
Proxy.SomeMethod(); // throw no endpoints discovered exception
Config:
<standardEndpoints>
<dynamicEndpoint>
<standardEndpoint name="discoveryDynamicEndpointConfiguration">
<discoveryClientSettings>
<findCriteria duration="00:00:05" maxResults="1">
<types>
<add name="AlarmServiceRef.IAlarmServer"/>
</types>
</findCriteria>
<endpoint kind="udpDiscoveryEndpoint"/>
</discoveryClientSettings>
</standardEndpoint>
</dynamicEndpoint>
</standardEndpoints>
Config:
<client>
<endpoint binding="basicHttpBinding" bindingConfiguration="DefaultBasicHttpBinding" contract="AlarmServiceRef.IAlarmServer" name="IAlarmServer"
kind="dynamicEndpoint"
endpointConfiguration="discoveryDynamicEndpointConfiguration"/>
</client>
Any ideas why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您通过 IIS 托管服务并进行发现时,需要注意以下几点:
类名包括命名空间
与客户一起。您可以手动浏览到服务的 .svc 文件
或使用 AppFabric 托管服务并将 AutoStart 设置为 true(您
也可以在 web.config 中指定)
在客户端上的查找条件中使用
以下是设置服务端点的服务器配置示例。请注意,服务“名称”属性是实现该服务的类的完整命名空间。
服务配置
还要确保将发现行为添加到服务
服务配置
中,因为我希望客户端能够通过类型(WcfDiscovery.Contracts.IAlarmServer)发现服务,所以我还必须在端点的行为配置中指定这一点( eb1)
服务配置
现在在客户端我可以使用 findCriteria 发现服务。请注意,查找条件中的类型必须与服务发出的类型相匹配(在服务类型列表中)
客户端配置
这是客户端端点配置
客户端配置
最后,我可以在控制台应用程序中发现服务,如下所示:
希望这个有帮助!
Couple of things when you're hosting a service with discovery via IIS
class name including the namespace
it with a client. You can manually browse to the service's .svc file
or host the service with AppFabric and set AutoStart to true (You
can also specify that in the web.config)
to use in the find criteria on the client
Here is a sample of the server configuration setting up the service endpoints. Note that the service "name" attribute is the full namespace to the class that is implementing the service.
Service Config
Also make sure to add the discovery behavior to the service
Service Config
Since I want clients to be able to discover the service by the type (WcfDiscovery.Contracts.IAlarmServer) I have to also specify that in the behavior configuration for the endpoint (eb1)
Service Config
Now on the client side I can discover the service using the findCriteria. Note that the type in the find criteria has to match the one emitted by the service (in the services types list)
Client Config
Here is the client endpoint configuration
Client Config
Finally, I can discover the service in a console app like this:
Hope this helps!
您不能只向您的客户端项目添加服务引用吗?它将为您生成配置。
Can't you just add a Service Reference to your client project? It will generate the configuration for you.