WCF mex 不包含来自主机的完整绑定信息

发布于 2024-11-07 01:15:53 字数 1422 浏览 0 评论 0原文

我正在发布一个带有用于元数据交换的 MEX 端点的服务,并且我使用下面的代码来发现它并获取元数据信息

DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindCriteria findCriteria =      FindCriteria.CreateMetadataExchangeEndpointCriteria(ContractType);
findCriteria.Duration = TimeSpan.FromSeconds(15);
findCriteria.MaxResults = 1;// MaxResults;

FindResponse result = discoveryClient.Find(findCriteria);
discoveryClient.Close();

ServiceEndpointCollection eps = MetadataResolver.Resolve(ContractType, result.Endpoints[0].Address);
return eps[0].Binding;

当我在客户端中获取元数据信息时,绑定信息 (OpenTimeout , ReceiveTimeoutSendTimeout)恢复为默认值。

这是主机中的绑定信息

<binding name="MyServiceBinding" closeTimeout="00:05:00" openTimeout="00:05:00"
      receiveTimeout="23:50:00" sendTimeout="00:05:00" maxReceivedMessageSize="50000000">
   <readerQuotas maxStringContentLength="50000000" maxArrayLength="50000000" />
   <reliableSession ordered="true" inactivityTimeout="00:01:00" enabled="false" />
   <security mode="None" />
</binding>

,这是我发现的另一个问题,与我的问题几乎相同。

WCF 服务绑定采用默认值而不是自定义值

我想知道我是否做错了什么或者我是否误解了元数据交换的概念。

我想做的是将所有必要的信息发送给我的客户,以便他们可以自行自动配置,并且没有任何硬代码配置。

I'm publishing a service with a MEX endpoint for metadata exchange and I'm using the code below to discover it and get the metadata information

DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindCriteria findCriteria =      FindCriteria.CreateMetadataExchangeEndpointCriteria(ContractType);
findCriteria.Duration = TimeSpan.FromSeconds(15);
findCriteria.MaxResults = 1;// MaxResults;

FindResponse result = discoveryClient.Find(findCriteria);
discoveryClient.Close();

ServiceEndpointCollection eps = MetadataResolver.Resolve(ContractType, result.Endpoints[0].Address);
return eps[0].Binding;

When I get the metadata information in my client the binding information (OpenTimeout,
ReceiveTimeout and SendTimeout) is back to its default values.

Here is the binding information in the host

<binding name="MyServiceBinding" closeTimeout="00:05:00" openTimeout="00:05:00"
      receiveTimeout="23:50:00" sendTimeout="00:05:00" maxReceivedMessageSize="50000000">
   <readerQuotas maxStringContentLength="50000000" maxArrayLength="50000000" />
   <reliableSession ordered="true" inactivityTimeout="00:01:00" enabled="false" />
   <security mode="None" />
</binding>

here is another question i've found that is almost the same as mine.

WCF Service Binding taking default values instead of custom values

I would like to know if I'm doing something wrong or if I misunderstood the concept of metadata exchange.

What I'm trying to do is send all the info necessary to my clients so they can auto config them self and do not have any hard code configuration.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情未る 2024-11-14 01:15:53

我不认为你做错了什么——你只是对元数据交换期望过高。

MEX 的目的是能够以编程方式发现新服务,并为这些服务创建客户端代理。为此,有 WSDL - 基本上 WSDL 中包含的任何内容都是元数据交换的一部分:

  • 服务契约/服务方法
  • 这些服务方法所需的参数
  • XML 模式中用于使用的数据类型的数据类型声明
  • 附加服务相关信息,例如使用的绑定等但

MEX 包含所有 WCF 特定配置设置 - 这是您所发现的。 MEX 将创建一个有效的客户端代理 - 但它从未打算将所有配置设置从服务器传输到客户端。您需要在客户端自己手动编写代码。

I don't think you're doing anything wrong - you're just expecting too much from the metadata exchange.

The purpose of MEX is to be able to discover new services programmatically, and create client-side proxies for those services. For this, there's the WSDL - basically anything contained in the WSDL is part of the metadata exchange:

  • service contract / service methods
  • parameters needed for those service methods
  • data type declarations in XML schema for the data types used
  • additional service related information like bindings used etc.

But MEX does not contain all WCF specific configuration settings - which is what you've discovered. MEX will create a functioning client-side proxy - but it never had the intention of transporting all configuration settings from the server to the client. You'll need to hand-code this yourself, on the client side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文