如何在Windows通用应用程序中使用双工合同消耗wcf服务?
当尝试在针对Windows 10(10.0; Build 10240)的Windows通用应用程序中使用双工wcf服务时,我会得到“PlatformNotSupportedExcetpion:此平台不支持操作。”运行时异常。
根据msdn,它是受支持的API。
如果不可能,我应该如何在我的情况下继续进行?我有两个应用程序(控制台和Windows通用xaml应用程序)在同一台机器上运行,我需要双向通信。
我有一个经典的.NET 4.6控制台应用程序,它创建了服务主机:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:8008/MyService"));
var binding = new NetTcpBinding(); //I've also tried net http binding
binding.Security.Mode = SecurityMode.None;
host.Description.Behaviors.Add(new ServiceMetadataBehavior());
host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexTcpBinding(),
"mex");
host.AddServiceEndpoint(typeof(IMyService), binding, "");
host.Open();
服务合同:
[ServiceContract(CallbackContract = typeof(IMyServiceCallback))]
public interface IMyService
{
[OperationContract(IsOneWay = true)]
void Initialize();
}
public interface IMyServiceCallback
{
[OperationContract(IsOneWay = true)]
void OnFrame(int i);
}
我尝试了ChannelFactory和通过“添加服务引用”对话框生成的wcf客户端,以及在UWP应用程序中使用NetHttpBinding和NetTcpBinding。
当我尝试创建wcf客户端实例时,它会抛出PlatformNotSupportedExcetpion异常。
来源:System.Private.ServiceModel
堆栈跟踪:
at System.ServiceModel.ReflectionExtensions.GetInterfaceMap(Type type, Type interfaceType)
at System.ServiceModel.Description.TypeLoader.GetIOperationBehaviorAttributesFromType(OperationDescription opDesc, Type targetIface, Type implType)
at System.ServiceModel.Description.TypeLoader.<>c__DisplayClass8.<AddBehaviorsFromImplementationType>b__10(Type currentType, KeyedByTypeCollection`1 behaviors)
at System.ServiceModel.Description.TypeLoader.AddBehaviorsAtOneScope[IBehavior,TBehaviorCollection](Type type, TBehaviorCollection descriptionBehaviors, ServiceInheritanceCallback`2 callback)
at System.ServiceModel.Description.TypeLoader.AddBehaviorsFromImplementationType(ServiceEndpoint serviceEndpoint, Type implementationType)
at System.ServiceModel.ChannelFactory`1.ReflectOnCallbackInstance(ServiceEndpoint endpoint)
at System.ServiceModel.ChannelFactory`1.CreateDescription()
at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address)
at System.ServiceModel.DuplexChannelFactory`1..ctor(Object callbackObject, Binding binding, EndpointAddress remoteAddress)
at System.ServiceModel.ClientBase`1..ctor(InstanceContext callbackInstance, Binding binding, EndpointAddress remoteAddress)
at System.ServiceModel.DuplexClientBase`1..ctor(InstanceContext callbackInstance, Binding binding, EndpointAddress remoteAddress)
at App1.ServiceReference1.MyServiceClientBase..ctor(InstanceContext callbackInstance)
at App1.ServiceReference1.MyServiceClient..ctor(MyServiceClientCallback callbackImpl)
at App1.ServiceReference1.MyServiceClient..ctor()
at App1.MainPage.<button_Click>d__1.MoveNext()
net.tcp
WCF服务。在迁移到Windows10后,我从头开始重新创建了该项目,现在我仍然遇到同样的PlatformNotSupportedException
错误。 - jsanalyticsAnyCPU
平台,除了新创建的UWP项目,它只接受/允许x86
或x64
平台,但不支持AnyCPU
。所以,我想问题就出在这里。我尝试过手动添加AnyCPU
到项目文件中...但当然没成功。再次强调,在Windows 8.1下没有任何问题,这可能与UWP项目模板或类似的问题有关。 - jsanalytics