consume c# .net wcf visual-studio-2008 wshttpbinding

c# - consume - Error de enlace mex en WCF



consume wcf service c# (3)

¿Puedo ir por la doble puntuación? :)

Cuando está utilizando WS-Http, está enlazando a un protocolo HTTPS, por lo que necesita usar el enlace MEX correcto;

<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />

Estoy utilizando VSTS 2008 + C # + .NET 3.0. Estoy usando un servicio WCF auto-alojado. Al ejecutar la siguiente declaración, aparece el siguiente error de "enlace no encontrado". He publicado todo mi archivo app.config, ¿alguna idea de lo que está mal?

ServiceHost host = new ServiceHost(typeof(MyWCFService));

Mensaje de error:

No se pudo encontrar una dirección base que coincida con el esquema http para el punto final con el enlace MetadataExchangeHttpBinding. Los esquemas de direcciones base registradas son [https].

Completo app.config:

<?xml version="1.0"?> <configuration> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="MyBinding" closeTimeout="00:00:10" openTimeout="00:00:20" receiveTimeout="00:00:30" sendTimeout="00:00:40" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="WeakWildcard" maxReceivedMessageSize="100000000" messageEncoding="Mtom" proxyAddress="http://foo/bar" textEncoding="utf-16" useDefaultWebProxy="false"> <reliableSession ordered="false" inactivityTimeout="00:02:00" enabled="true" /> <security mode="Transport"> <transport clientCredentialType="Digest" proxyCredentialType="None" realm="someRealm" /> </security> </binding> </wsHttpBinding> </bindings> <services> <service name="MyWCFService" behaviorConfiguration="mexServiceBehavior"> <host> <baseAddresses> <add baseAddress="https://localhost:9090/MyService"/> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MyBinding" contract="IMyService"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="mexServiceBehavior"> <serviceMetadata httpGetEnabled="True"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> <startup><supportedRuntime version="v2.0.50727"/></startup></configuration>


He hecho una pregunta en un comentario para la answer

¿Es posible tener IMetadataExchange para http y https como puntos finales separados?

marc_s respondió

debe ser capaz de definir una segunda dirección base, para http: // y usarla para el punto final http mex.

Entonces, la solución es declarar múltiples puntos finales con la MISMA dirección = "mex" y diferentes enlaces como los siguientes

<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />   <endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex"/>

Recientemente descubrí que es más fácil tener un interruptor de configuración que se puede usar para habilitar MEX en la prueba y deshabilitarlo en Live.

De http://msdn.microsoft.com/en-us/library/aa395224.aspx

Es posible usar la clase ServiceHostFactory para crear una costumbre derivada de ServiceHost en Internet Information Services (IIS ServiceHost personalizado que agrega el ServiceMetadataBehavior, que habilita la publicación de metadatos), incluso si este comportamiento no se agrega explícitamente en el archivo de configuración del servicio.

Escriba el código imperativo que permite la publicación de metadatos una vez y luego reutilice ese código en varios servicios diferentes. Esto se logra al crear una nueva clase que deriva de ServiceHost y reemplaza el método ApplyConfiguration () para agregar imperativamente el comportamiento de publicación de metadatos.

Código de ejemplo del http://msdn.microsoft.com/en-us/library/aa395224.aspx

//Add a metadata endpoint at each base address //using the "/mex" addressing convention foreach (Uri baseAddress in this.BaseAddresses) { if (baseAddress.Scheme == Uri.UriSchemeHttp) { mexBehavior.HttpGetEnabled = true; this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); } else if (baseAddress.Scheme == Uri.UriSchemeHttps) { mexBehavior.HttpsGetEnabled = true; this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex"); } else if (baseAddress.Scheme == Uri.UriSchemeNetPipe) { this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex"); } else if (baseAddress.Scheme == Uri.UriSchemeNetTcp) { this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); } }


La dirección base para su servicio define "HTTPS: //", pero su dirección de mex es "HTTP".

Si desea que su servicio use https: //, también deberá usar mexHttpsBinding :

<services> <service name="MyWCFService" behaviorConfiguration="mexServiceBehavior"> <host> <baseAddresses> <add baseAddress="https://localhost:9090/MyService"/> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MyBinding" contract="IMyService" /> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> </service> </services>

Bagazo