C# 如何在WinForm中调用AppService

C# 如何在WinForm中调用AppService,c#,winforms,C#,Winforms,当我在UWP应用程序上调用AppService时,AppServiceConnectionStatus返回Success。但是,当我在winform客户端上调用AppService时,AppServiceConnectionStatus仍然返回AppServiceUnavailable。UWP,Winform客户端代码相同,以下是UWP和Winform中的相同代码: var appService = new AppServiceConnection(); // Here, we

当我在UWP应用程序上调用AppService时,AppServiceConnectionStatus返回Success。但是,当我在winform客户端上调用AppService时,AppServiceConnectionStatus仍然返回AppServiceUnavailable。UWP,Winform客户端代码相同,以下是UWP和Winform中的相同代码:

var appService = new AppServiceConnection();

        // Here, we use the app service name defined in the app service provider's Package.appxmanifest file in the <Extension> section.
        appService.AppServiceName = "com.yanscorp.appservicedemo.Values";

        // Use Windows.ApplicationModel.Package.Current.Id.FamilyName within the app service provider to get this value.
        appService.PackageFamilyName = "c97887ad-1f75-4b48-9e3b-21b89c061715_6evysfdvxt248";

        //uwp return Success,but winform return AppServiceUnavailable
        var status = await appService.OpenAsync();
        if (status != AppServiceConnectionStatus.Success)
        {
            textBlock.Text = "Failed to connect";
            return;
        }
var-appService=new-AppServiceConnection();
//在这里,我们使用在部分中的app service provider的Package.appxmanifest文件中定义的app service名称。
appService.AppServiceName=“com.yanscorp.appservicedemo.Values”;
//在应用程序服务提供程序内使用Windows.ApplicationModel.Package.Current.Id.FamilyName获取此值。
appService.PackageFamilyName=“c97887ad-1f75-4b48-9e3b-21b89c061715_6evysfdvxt248”;
//uwp返回成功,但winform返回AppServiceUnavailable
var status=await-appService.OpenAsync();
if(状态!=AppServiceConnectionStatus.Success)
{
textBlock.Text=“连接失败”;
返回;
}

如果双击启动应用程序,我可以从Winform应用程序成功使用AppService。但是,如果我从VS调试应用程序,它确实无法连接到服务(状态未知)。这让我怀疑VS是否拦截了连接。这是你的案子吗?在VS中调试?非常感谢您的提醒。我处于VS模式。我应该先启动uwp,然后手动启动WinForm。根据设计,我在测试中也验证了这一点,在尝试连接时,公开服务(服务提供商)的uwp应用程序不必运行。请求到来时会触发。是的,非常感谢您的帮助