2013-07-26 16 views
6

To naprawdę mnie dręczy przez kilka godzin. Stworzyłem najprostszą usługę WCF przy użyciu powiązania TCP.Wiązanie TCP netto: prefiks URI nie jest rozpoznawany

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); 
    } 
} 

plik Web.config ma następującą sekcję:

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

Usługa ta jest obsługiwana w IIS:

detailed settings

Teraz, gdy próbuje dodać odwołanie do net.tcp://localhost:808/WcfTcpService.TestTcpService od aplikacja kliencka, nadal otrzymuję błąd:

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. 

Usługa net.tcp jest uruchomiona, pojawia się ten sam błąd co WcfTestClient.exe. i mogę z powodzeniem uruchomić http://localhost/WcfTcpService/TestTcpService.svc.

Szukałem google, ale nic nie wyskoczyło.

Dzięki!

EDIT:

Ekran powiązań z 'Default Web Site' wygląda tak btw:

bindings

+1

Czy ten błąd po wybraniu opcji "Add Reference Service"? Wypróbuj adres http: //localhost/WcfTcpService/TestTcpService.svc w tym oknie dialogowym. – empi

+0

Sprawdź powiązania w IIS/IIS wyrazić Zobacz na to pytanie: http://stackoverflow.com/questions/3188618/enabling-net-tcp – nakchak

+0

@empi Musicie być żartujesz ... że Prace. Jeśli opublikujesz to jako rozwiązanie, zaakceptuję to. Dzięki! – Nullius

Odpowiedz

8

Po utworzeniu usługi korzystające netTcpBinding i chcesz dodać odniesienie usług w Visual Studio powinieneś używać adresu http (httpGetEnabled), a nie rzeczywistego adresu tcp, którego usługa nasłuchuje. Rozwiązaniem było więc ustawienie localhost/WcfTcpService/TestTcpService.svc jako adresu URL w oknie dialogowym Add service reference.

+1

Po prostu być kompletnym: w rzeczywistości jest to 'net.tcp: // localhost/WcfTcpService/TestTcpService.svc', który rozwiązał problem. – Nullius

0

miałem ten sam problem i zmieniłem web.config jak poniżej:

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

Powiązane problemy