2009-06-22 10 views
15

Sto utilizzando VSTS 2008 + C# + .NET 3.0. Sto usando un servizio WCF auto-ospitato. Quando si esegue la seguente dichiarazione, è presente il seguente errore "associazione non trovata". Ho pubblicato il mio intero file app.config, qualche idea su cosa c'è che non va?errore di associazione mex in WCF

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

Messaggio di errore:

Impossibile trovare un indirizzo di base che corrisponde schema http per il endpoint con legame MetadataExchangeHttpBinding. Gli schemi di indirizzi di base registrati sono [https].

app.config completa:

<?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> 

risposta

44

L'indirizzo di base per il vostro servizio definisce "https: //" - ma il tuo indirizzo mex è "HTTP".

Se si desidera che il servizio da utilizzare https: //, è necessario utilizzare il mexHttpsBinding così:

<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> 

Marc

+0

E 'possibile avere IMetadataExchange per HTTP e HTTPS come endpoint separate? Quale dovrebbe essere il loro indirizzo? –

+0

La mia domanda riguardava http: e https, non il protocollo net.tcp. –

+0

@MichaelFreidgeim: scusa - ho letto male. Ma lo stesso vale: dovresti essere in grado di definire un secondo indirizzo di base, per 'http: //' e usarlo per l'endpoint http mex. –

12

Posso andare per il doppio punteggio? :)

Poiché si utilizza WS-Http, si sta vincolando a un protocollo HTTPS, quindi è necessario utilizzare il binding MEX corretto;

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

ho chiesto una domanda in un commento per Marc_sanswer

E 'possibile avere IMetadataExchange per HTTP e HTTPS come endpoint separate?

marc_s risposto

si dovrebbe essere in grado di definire un secondo indirizzo di base, per http: // e uso che per la http mex endpoint.

Quindi la soluzione è quella di dichiarare più endpoint con l'indirizzo STESSA = "mex" e diversi attacchi come la seguente

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

Recentemente ho scoperto che è più facile avere un interruttore di configurazione che può essere usato per abilitare MEX su test e disabilitare su Live.

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

E 'possibile utilizzare la classe ServiceHostFactory per creare un costume derivato dal ServiceHost in Internet Information Services (ServiceHost personalizzati IIS che aggiunge il ServiceMetadataBehavior, (che consente la pubblicazione di metadati), anche se questo comportamento non è esplicitamente aggiunto nel file di configurazione del servizio.

Scrivere il codice imperativo che consente la pubblicazione dei metadati una volta e quindi riutilizzare tale codice tra diversi servizi diversi. Questo è realizzato creando una nuova classe che deriva da ServiceHost e sovrascrive il metodo ApplyConfiguration() per aggiungere imperativamente il comportamento di pubblicazione dei metadati .

codice di esempio da Custom Service Host MSDN article

//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"); 
    } 
} 
Problemi correlati