tags:

views:

458

answers:

1
+1  Q: 

Problem using Mex

My application uses both NetTcpBinding and BasicHttpBinding but each of them will expose a subset of my service class. I have created the service as below.

The problem is that even though I just added 3 of my contracts to the Mex binding, all of the contracts are shown when I want to add the service to my project.

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();
A: 

I think that the only way you can acomplish this is to create 2 separate service host. One for the services to be exposed via http and one for those exposed via net.tcp binding.

Shiraz Bhaiji