![](/img/trans.png)
[英]How to access WCF service from Remote Desktop to another machine in c# application?
[英]Start WCF service application from another application (C#)
我有WCF服務應用程序和Windows窗體應用程序。 我想從WCF中獲取一些數據,但是只能從IDE自動啟動。
我的問題很簡單:如何從Windows窗體應用程序啟動WCF服務應用程序?
UPD:這兩個應用程序具有不同的位數,因此不能在同一進程中托管。
您可以使用ServiceHost類
像這樣的東西
public static void Main()
{
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
{
try
{
// Open the ServiceHost to start listening for messages.
serviceHost.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.ReadLine();
// Close the ServiceHost.
serviceHost.Close();
}
catch (TimeoutException timeProblem)
{
Console.WriteLine(timeProblem.Message);
Console.ReadLine();
}
catch (CommunicationException commProblem)
{
Console.WriteLine(commProblem.Message);
Console.ReadLine();
}
}
}
但是您可以輕松地使其適應Winform,或者如果需要,可以在托管Windows服務中托管WCF服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.