Der Versuch, eine einfache Demo von NetTcpBinding zu erhalten, um es in ein anderes Projekt zu erweitern.NetTcpBinding - Self-Hosted WCF - Client kann nicht verbunden werden
Architektur: 2 Konsolen-Apps (1 Host/Server, 1 Client) und 1 Typbibliotheksprojekt. Beide Konsolen-Apps haben einen Verweis auf das Typbibliotheksprojekt.
Host-Anwendung:
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}");
}
}
Client-Anwendung:
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();
}
Type Library:
[ServiceContract]
public interface IHelloWorld
{
[OperationContract]
void HelloWorld();
[OperationContract]
void WriteMe(string text);
}
I belie habe ich alle notwendigen Dienste installiert und läuft:
Offensichtlich zur Laufzeit alle die Config zu tun, ich versuche.
Ich erhalte diese Fehlermeldung konsequent auf dem Client:
Hervorrufen von Hello World auf TcpService.
Ausnahme: Es gab keinen Endpunkt bei net.tcp hören: //127.0.0.1: 1234/Helloworld /, die die Nachricht akzeptieren könnte. Dies wird oft durch eine falsche Adresse oder eine falsche SOAP-Aktion verursacht. Weitere Informationen finden Sie unter InnerException, falls vorhanden. Drücken Sie zum Beenden die Eingabetaste.
Fehle ich etwas offensichtlich?
Gibt es eine innere Ausnahme? Wird die Host-Anwendung beim Ausführen des Clients ausgeführt? Wird die Host-Anwendung unter einem Konto mit Administratorrechten ausgeführt? – Tim
InnerException ist leer. Es wird mit Administratorrechten ausgeführt und schlägt (ordnungsgemäß) fehl, wenn es ohne ausgeführt wird. FWIW: Ich hatte das mit http-Bindings, aber ich habe versucht, zu netTcp zu wechseln, weil ich keine admin privs benutzen wollte. Darf ich jedoch auf diese Idee verzichten müssen. –