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);
}
私は必要なすべてのインストールサービスと実行していまし:
明らか私は、実行時にすべての設定をやろうとしています。
は、私は一貫して、クライアントにこのエラーメッセージが表示されます。
の呼び出しのHelloWorld TcpServiceに。
例外://127.0.0.1:1234/HelloWorldService/ メッセージを受け入れることができる net.tcpで聞いて何のエンドポイントがありませんでした。これは、しばしば不正なアドレスまたはSOAPアクションによって引き起こされます。 詳細については、InnerException(存在する場合)を参照してください。 Enterを押して終了します。
明らかなものがありませんか?
内部例外はありますか?クライアントの実行時にホストアプリケーションが実行されていますか?ホストアプリケーションは管理者特権を持つアカウントで実行されていますか? – Tim
InnerExceptionが空です。管理者特権で実行されており、実行されていないと正常に動作しません。 FWIW:これはhttpバインディングで実行していましたが、管理者権限を使用したくないのでnetTcpに切り替えようとしました。しかし、そのアイデアをあきらめなければならないかもしれません。 –