During my developing my tool for file transferring with TCP protocol in WCF. I met an annoyed error saying:
Metadata contains a reference that cannot be resolved: ‘net.tcp://localhost:7633/ClientTransferring/mex’.
Could not connect to net.tcp://localhost:7633/ClientTransferring/mex. The connection attempt lasted for a time span of 00:00:02.0117187. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:7633.
No connection could be made because the target machine actively refused it 127.0.0.1:7633
If the service is defined in the current solution, try building the solution and adding the service reference again.
As I read this error I thought that I forgot to add a service end point. In WCF, the service can also publish its metadata over a special endpoint called the metadata exchange endpoint, sometimes referred to as the MEX endpoint. That endpoint supports an industry standard for exchanging metadata, represented in WCF by the IMetadataExchange interface
[ServiceContract(...)] public interface IMetadataExchange { [OperationContract(...)] Message Get(Message request); //More members }
The details of this interface are inconsequential. Like most of these industry standards, it is difficult to implement. Fortunately, WCF can have the service host automatically provide the implementation of IMetadataExchange and expose the metadata exchange endpoint. All you need to do is designate the address and the binding to use, as well as add the service metadata behavior. For the bindings, WCF provides dedicated binding transport elements for the HTTP, HTTPS, TCP, and IPC protocols. For the address, you can provide a full address or use any of the registered base addresses. There is no need to enable the HTTP-GET option, but there is no harm either.
Like any other endpoint, you can only add a metadata exchange endpoint programmatically before opening the host. WCF does not offer a dedicated binding type for the metadata exchange endpoint. Instead, you need to construct a custom binding that uses the matching transport binding element, and then provide that binding element as a construction parameter to an instance of a custom binding. Finally, call the AddServiceEndpoint( ) method of the host providing it with the address, the custom binding, and the IMetadataExchange contract type.
ServiceMetadataBehavior smbBehavior = m_shHost.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (smbBehavior == null) { smbBehavior = new ServiceMetadataBehavior(); m_shHost.Description.Behaviors.Add(smbBehavior); } m_shHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "net.tcp://localhost:" + (CustomConfiguration.Port - 1).ToString() + CustomConfiguration.ServiceName + "/mex"); m_shHost.Open();
But after adding this code I still could not solve this error. After 30 minutes of “cursing” Microsoft on this silly error I found out that I enter the wrong URL. The “transferring” word should be with 2 ‘r’ but in my source code I only tipped 1 ‘r’ and so I can not make a reference to it.
Thank you so much…I had the same error and it was solved by your useful comment…
@Sepideh: I’m glad that I can help you.