2013-03-07 13 views
12

Mam usługę WCF, którą przetestowałem , kopiując jej interfejsy do przykładowego projektu klienta.
Teraz chcę działać poprawnie, dodając odwołanie do usługi.
Usługa jest hostowana w systemie Windows Hosting (przy użyciu installUtil).
Usługa ma 2 projekty - zewnętrzne (interfejsy + datacontracts) i wewnętrzne (implementacje).
Z jakiegoś powodu to nie miało app.config więc dodałem jedną ręcznie:Dodaj odwołanie do usługi podczas używania wiązania netTcp

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="ExecutionService" behaviorConfiguration="Default"> 
     <endpoint name="TCPEndpoint" address="" binding ="netTcpBinding" contract="Externals.IExecutionService"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:3040/ExecutionService"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Default"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

Próbując dodać odwołanie usług od mojego klienta próbki powoduje następujący błąd:

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:3040/ExecutionService/Externals.IExecutionService'. 
There was no endpoint listening at net.tcp://localhost:3040/ExecutionService/Externals.IExecutionService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 
If the service is defined in the current solution, try building the solution and adding the service reference again. 

I zobaczyłem here, że nie ma potrzeby w app.config.
Jestem trochę zdezorientowany i jestem początkującym z WCF.
W jaki sposób miła aplikacja WPF może odwoływać się do mojej usługi? Chcę, aby usługa była hostowana w systemie Windows i nie chcę przeciągać bibliotek DLL ze mną.

Edit
Dodałem punkt końcowy metadanych i mój appconfig teraz wygląda tak:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="ExecutionService" behaviorConfiguration="Default"> 
     <endpoint name="TCPEndpoint" 
        address="" 
        binding ="netTcpBinding" 
        contract="Externals.IExecutionService"/> 
     <endpoint address="mex" 
        binding="maxHttpBinding" 
        contract="Externals.IExecutionService"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:3040/ExecutionService"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Default"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

Próbowałem dodanie odniesienia usługa, za pomocą net.tcp://localhost:3040/ExecutionServicenet.tcp://localhost:3040/ExecutionService/Externals i net.tcp://localhost:3040/ExecutionService/Externals/IExecutionService a ja wciąż się samo błąd.

Odpowiedz

26

Co trzeba zrobić:

  1. maxHttpBinding -> mexTcpBinding - nie można używać mexHttpBinding na Net.TCP końcowego (i to nie mex max)
  2. kontrakt dla mex punkt końcowy musi być IMetadataExchange - jeśli chcesz mieć metadane usługi dostępne przez ten punkt końcowy
  3. httpGetEnabled = "false", ponieważ nie będzie http punktu końcowego, aby uzyskać metadane z
  4. Kiedy testuje rozwiązania w prosty przyjmującym konsoli Musiałem zmienić nazwę w < usługi > tag Externals.ExecutionService (ale to zależy od tego jak instancję usługi)

Wtedy twój odniesienie usługa będzie są dostępne na stronie: net.tcp://localhost:3040/ExecutionService/mex jako adres bazowy jest net.tcp://localhost:3040/ExecutionService i względnej adres punktu końcowego mex jest ustawiony mex

końcowe app.config poniżej:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<system.serviceModel> 
<services> 
    <service name="Externals.ExecutionService" behaviorConfiguration="Default"> 
    <endpoint name="TCPEndpoint" 
       address="" 
       binding ="netTcpBinding" 
       contract="Externals.IExecutionService"/> 
    <endpoint address="mex" 
       binding="mexTcpBinding" 
       contract="IMetadataExchange"/> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://localhost:3040/ExecutionService"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="Default"> 
     <serviceMetadata httpGetEnabled="false" /> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
</system.serviceModel> 
</configuration> 

Aby szybko sprawdzić, czy konfiguracja jest prawidłowa, użyłem aplikacji hosta konsoli jako hosta usługi. Program.cs:

using System; 
using System.ServiceModel; 

namespace Externals 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

      var sh=new ServiceHost(typeof(ExecutionService)); 
      sh.Open(); 
      Console.WriteLine("Service running press any key to terminate..."); 
      Console.ReadKey(); 
      sh.Close(); 
     } 
    } 
} 

Uruchom aplikację konsoli i próbować dodać odniesienie do projektu usług poprzez net.tcp://localhost:3040/ExecutionService/mex.

2

Zmień to:

<endpoint address="mex" 
        binding="maxHttpBinding" 
        contract="Externals.IExecutionService"/> 

Do:

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

Wskazówka to nie maxHttpBinding ale mexTcpBinding, trzeba było typo również tam.

Powiązane problemy