【问题标题】:Problem using Mex使用 Mex 的问题
【发布时间】:2008-11-08 14:33:09
【问题描述】:

我的应用程序同时使用 NetTcpBinding 和 BasicHttpBinding,但它们中的每一个都会公开我的服务类的一个子集。我创建了如下服务。

问题是,即使我刚刚将 3 个合同添加到 Mex 绑定,当我想将服务添加到我的项目时,所有合同都会显示。

m_ServiceHost = new ServiceHost(typeof(Services), baseAddresses); 

BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); 
basicHttpBinding.UseDefaultWebProxy = false; 

m_ServiceHost.AddServiceEndpoint(typeof( IMyFirstService), basicHttpBinding, "MyFirstService"); 
m_ServiceHost.AddServiceEndpoint(typeof(IMySecondService), basicHttpBinding, "MySecondService"); 
m_ServiceHost.AddServiceEndpoint(typeof(IMyThirdService), basicHttpBinding, "MyThirdService"); 

NetTcpBinding netTcpBinding = new NetTcpBinding(); 
netTcpBinding.MaxReceivedMessageSize = 2147483647; 
netTcpBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647; 

m_ServiceHost.AddServiceEndpoint(typeof(IMyFirstService), netTcpBinding, "MyFirstService"); 
m_ServiceHost.AddServiceEndpoint(typeof(IMySecondService), netTcpBinding, "MySecondService"); 
m_ServiceHost.AddServiceEndpoint(typeof(IMyFourthService), netTcpBinding, "MyFourthService"); 
m_ServiceHost.AddServiceEndpoint(typeof(IMyFifthService), netTcpBinding, "MyFifthService"); 
m_ServiceHost.AddServiceEndpoint(typeof(IMySixService), netTcpBinding, "MySixService"); 


HttpTransportBindingElement httpTransport = new HttpTransportBindingElement(); 
httpTransport.MaxReceivedMessageSize = 2147483647; 
httpTransport.MaxBufferSize = 2147483647; 

TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(); 
textMessageEncoding.ReaderQuotas.MaxDepth = 2147483647; 
textMessageEncoding.ReaderQuotas.MaxStringContentLength = 2147483647; 
textMessageEncoding.ReaderQuotas.MaxArrayLength = 2147483647; 
textMessageEncoding.ReaderQuotas.MaxBytesPerRead = 2147483647; 
textMessageEncoding.ReaderQuotas.MaxNameTableCharCount = 2147483647;               

System.ServiceModel.Channels.CustomBinding mexHttpCustomBinding = new System.ServiceModel.Channels.CustomBinding(textMessageEncoding, httpTransport); 
mexHttpCustomBinding.Name = "MexHttpBindingConfig"; 
               m_ServiceHost.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), mexHttpCustomBinding, "mex"); 

m_ServiceHost.Open(); 

【问题讨论】:

标签: .net wcf


【解决方案1】:

我认为实现此目的的唯一方法是创建两个单独的服务主机。一种用于通过 http 公开的服务,另一种用于通过 net.tcp 绑定公开的服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    相关资源
    最近更新 更多