經過Http的方式提供metadatatcp
<system.serviceModel> <services> <service name = "MyService" behaviorConfiguration = "MEXGET"> <host> <baseAddresses> <add baseAddress = "http://localhost:8000/"/> </baseAddresses> </host> ... </service> <service name = "MyOtherService" behaviorConfiguration = "MEXGET"> <host> <baseAddresses> <add baseAddress = "http://localhost:8001/"/> </baseAddresses> </host> ... </service> </services> <behaviors> <serviceBehaviors> <behavior name = "MEXGET"> <serviceMetadata httpGetEnabled = "true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
通常經過HTTP的基地址便可以訪問元數據,也能夠指定不一樣的地址:spa
<behavior name = "MEXGET"> <serviceMetadata httpGetEnabled = "true" httpGetUrl = "MyMEXAddress"/> </behavior>
ServiceHost host = new ServiceHost(typeof(MyService)); ServiceMetadataBehavior metadataBehavior; metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>(); if(metadataBehavior == null) { Debug.Assert(BaseAddresses.Any(baseAddress=>baseAddress.Uri.Scheme == "http")); metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetEnabled = true; host.Description.Behaviors.Add(metadataBehavior); } host.Open();
平臺無關的元數據交換方式,支持多種協議code
<services> <service name = "MyService" behaviorConfiguration = "MEX"> <host> <baseAddresses> <add baseAddress = "net.tcp://localhost:8001/"/> <add baseAddress = "net.pipe://localhost/"/> </baseAddresses> </host> <endpoint address = "MEX" binding = "mexTcpBinding" contract = "IMetadataExchange" /> <endpoint address = "MEX" binding = "mexNamedPipeBinding" contract = "IMetadataExchange" /> <endpoint address = "http://localhost:8000/MEX" binding = "mexHttpBinding" contract = "IMetadataExchange" /> ... </service> </services> <behaviors> <serviceBehaviors> <behavior name = "MEX"> <serviceMetadata/> </behavior> </serviceBehaviors> </behaviors>