2013-07-26 9 views
6

Questo mi disturba per un paio d'ore. Ho creato il servizio WCF più semplice utilizzando un binding TCP.Binding TCP netto: il prefisso URI non viene riconosciuto

namespace WcfTcpService 
{ 
    public class TestTcpService : ITestTcpService 
    { 
     public string Hello(string name) 
     { 
      return "Hello, " + name + "!"; 
     } 
    } 
} 

namespace WcfTcpService 
{ 
    [ServiceContract] 
    public interface ITestTcpService 
    { 
     [OperationContract] 
     string Hello(string name); 
    } 
} 

file web.config ha la seguente sezione:

<system.serviceModel> 
    <services> 
     <service name="WcfTcpService.TestTcpService" behaviorConfiguration="TestServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:808/WcfTcpService.TestTcpService" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding" contract="WcfTcpService.ITestTcpService"></endpoint> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"></endpoint> 
     </service> 
    </services> 
    <bindings> 
     <netTcpBinding> 
     <binding name="tcpBinding" portSharingEnabled="true"> 
      <security mode="None"></security> 
     </binding> 
     </netTcpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="TestServiceBehavior"> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <!--<protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
     <add binding="netTcpBinding" scheme="net.tcp" /> 
    </protocolMapping>-->  
    <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />--> 
    </system.serviceModel> 

Questo servizio è ospitato in IIS:

detailed settings

Ora, quando si cerca di aggiungere un riferimento a net.tcp://localhost:808/WcfTcpService.TestTcpService da un'applicazione client, continuo a ricevere l'errore:

The URI prefix is not recognized. 
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/WcfTcpService.TestTcpService'. 
The message could not be dispatched because the service at the endpoint address 'net.tcp://localhost/WcfTcpService.TestTcpService' is unavailable for the protocol of the address. 
If the service is defined in the current solution, try building the solution and adding the service reference again. 

Il servizio net.tcp è in esecuzione, ricevo lo stesso errore con WcfTestClient.exe. e posso eseguire con successo http://localhost/WcfTcpService/TestTcpService.svc.

Ho cercato su google ma non è venuto fuori nulla.

Grazie!

EDIT:

Lo schermo attacchi del 'sito Web predefinito' assomiglia a questo proposito:

bindings

+1

Non si ottiene questo errore quando si sceglie "Aggiungi riferimento al servizio"? Prova l'indirizzo http: //localhost/WcfTcpService/TestTcpService.svc in questa finestra di dialogo. – empi

+0

Controllare le associazioni in IIS/iis esprimono Vai a questa domanda: http://stackoverflow.com/questions/3188618/enabling-net-tcp – nakchak

+0

@empi Hai avuto modo di essere scherzando ... che lavori. Se pubblichi questo come soluzione, lo accetterò. Grazie! – Nullius

risposta

8

Quando si crea servizio che utilizza netTcpBinding e si desidera aggiungere riferimento al servizio in Visual Studio è necessario utilizzare l'indirizzo http (httpGetEnabled) non il vero indirizzo TCP sul quale il servizio è in ascolto. Quindi la soluzione era quella di impostare localhost/WcfTcpService/TestTcpService.svc come url nella finestra di dialogo Aggiungi riferimento servizio.

+1

Solo per essere completa: in realtà 'net.tcp: // localhost/WcfTcpService/TestTcpService.svc' ha funzionato. – Nullius

0

Ho avuto lo stesso problema e ho cambiato web.config, come di seguito:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true"> 
 
     <baseAddressPrefixFilters> 
 
     <add prefix="net.tcp://YourBaseUrl"/> 
 
     </baseAddressPrefixFilters> 
 
    </serviceHostingEnvironment>

Problemi correlati