다른 프로젝트로 확장하기 위해 노력 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에.
예외 : net.tcp에서 듣기에는 엔드 포인트가 없었다 : //127.0.0.1 : 1234/HelloWorldService /를 메시지를 받아 들일 수 있었다. 이것은 종종 잘못된 주소 또는 SOAP 조치로 인해 발생합니다. 자세한 내용은 InnerException을 참조하십시오. 종료하려면 Enter 키를 누릅니다.
오전 내가 뭔가를 분명 실종?
내부 예외가 있습니까? 클라이언트를 실행할 때 호스트 응용 프로그램이 실행 중입니까? 호스트 응용 프로그램이 관리자 권한을 가진 계정으로 실행되고 있습니까? – Tim
InnerException이 비어 있습니다. 관리자 권한으로 실행 중이며, 실행하지 않을 경우 (정상적으로) 실패합니다. FWIW : 저는 http 바인딩을 사용하여이 작업을 수행했지만 관리자 권한을 사용하지 않으려 고 netTcp로 전환하려고했습니다. 그래도 그 생각을 포기해야 할 수도 있습니다. –