2016-06-17 14 views
3

NetTcpBindingを簡単にデモして別のプロジェクトに展開しようとしています。NetTcpBinding - 自己ホストWCF - クライアントを接続できません

アーキテクチャ:2つのコンソールアプリケーション(1つのホスト/サーバー、1つのクライアント)と1つのタイプライブラリプロジェクト。両方のコンソールアプリケーションには、タイプライブラリプロジェクトへの参照があります。

ホストアプリケーション:

class Program 
{ 
    static void Main() 
    { 
     var netTcpBinding = new NetTcpBinding(SecurityMode.None) 
     { 
      PortSharingEnabled = true 
     }; 

     var netTcpAdddress = new Uri("net.tcp://127.0.0.1:1234/HelloWorldService/"); 

     var tcpHost = new ServiceHost(typeof(HelloWorldService), netTcpAdddress); 
     tcpHost.AddServiceEndpoint(typeof(IHelloWorld), netTcpBinding, "IHelloWorld"); 

     tcpHost.Open(); 
     Console.WriteLine($"tcpHost is {tcpHost.State}. Press enter to close."); 

     Console.ReadLine(); 
     tcpHost.Close(); 
    } 
} 


public class HelloWorldService : IHelloWorld 
{ 
    public void HelloWorld() 
    { 
     Console.WriteLine("Hello World!"); 
    } 

    public void WriteMe(string text) 
    { 
     Console.WriteLine($"WriteMe: {text}"); 
    } 
} 

クライアントアプリケーション:

static void Main() 
    { 
     Console.WriteLine("Press enter when the service is opened."); 
     Console.ReadLine(); 


     var endPoint = new EndpointAddress("net.tcp://127.0.0.1:1234/HelloWorldService/"); 
     var binding = new NetTcpBinding(); 
     var channel = new ChannelFactory<IHelloWorld>(binding, endPoint); 
     var client = channel.CreateChannel(); 

     try 
     { 
      Console.WriteLine("Invoking HelloWorld on TcpService."); 
      client.HelloWorld(); 
      Console.WriteLine("Successful."); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine($"Exception: {ex.Message}"); 
     } 

     Console.WriteLine("Press enter to quit."); 
     Console.ReadLine(); 
    } 

タイプライブラリ:私は裏切る

[ServiceContract] 
public interface IHelloWorld 
{ 
    [OperationContract] 
    void HelloWorld(); 

    [OperationContract] 
    void WriteMe(string text); 
} 

私は必要なすべてのインストールサービスと実行していまし:

明らか

enter image description here

私は、実行時にすべての設定をやろうとしています。

は、私は一貫して、クライアントにこのエラーメッセージが表示されます。

の呼び出しのHelloWorld TcpServiceに。

例外://127.0.0.1:1234/HelloWorldService/ メッセージを受け入れることができる net.tcpで聞いて何のエンドポイントがありませんでした。これは、しばしば不正なアドレスまたはSOAPアクションによって引き起こされます。 詳細については、InnerException(存在する場合)を参照してください。 Enterを押して終了します。

明らかなものがありませんか?

+0

内部例外はありますか?クライアントの実行時にホストアプリケーションが実行されていますか?ホストアプリケーションは管理者特権を持つアカウントで実行されていますか? – Tim

+0

InnerExceptionが空です。管理者特権で実行されており、実行されていないと正常に動作しません。 FWIW:これはhttpバインディングで実行していましたが、管理者権限を使用したくないのでnetTcpに切り替えようとしました。しかし、そのアイデアをあきらめなければならないかもしれません。 –

答えて

1

アドレスでエンドポイントを公開しているあなたのサービス:

net.tcp://127.0.0.1:1234/HelloWorldService/IHelloWorld

が、あなたのクライアントが接続している:

net.tcp://127.0.0.1:1234/HelloWorldService/

あなたはまた、クライアントに設定する必要がありますNetTcpBindingSecurityModeサーバー(None)と同じです。

+0

あなたはそれを釘付けにしました!私は、パスがインターフェイス名で拡張されていることを認識していませんでした。ありがとうございました!読者の皆さん:セキュリティ= {Mode = SecurityMode.None}を私のバインディングイニシャライザに追加し、endPoint = new EndpointAddress( "net.tcp://127.0.0.1:1235/HelloWorldService/IHelloWorld")を設定すると、すべて解決されました! –

関連する問題