如何在Windows通用应用程序中使用具有双面合同的wcf服务? (;建立10240 10.0)如何在Windows通用应用程序中使用双工wcf服务
根据msdn它支持的API
当试图在Windows通用应用程序消耗双工WCF服务,针对Windows 10我得到PlatformNotSupportedExcetpion: Operation is not supported on this platform.
运行时异常。
如果这是不可能的,我应该如何继续我的方案?我有两个应用程序(控制台和Windows通用xaml应用程序)在同一台机器上运行,我需要双向通信。
我CLASIC .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()
我有一个UWP客户端应用程序,它可以很好地连接到双工'net.tcp' WCF服务。迁移到Windows10后,我重新创建了该项目,现在我得到了同样的'PlatformNotSupportedException'。 – jsanalytics
我在这个特定的解决方案中有23个项目。除了新创建的UWP项目外,他们都使用'AnyCPU'平台,只接受/允许'x86'或'x64'平台,而不是'AnyCPU'。所以,我想这就是问题来自何处。我试图搞乱项目文件,手动添加'AnyCPU' ......但当然这并不顺利。再次,这用于在Windows 8.1下无任何问题。 UWP项目模板可能存在一些问题,或者具有这种性质。 – jsanalytics
另一个线程中的人注意到这一点。在删除CallbackContract属性后,UWP客户端可以创建一个连接,所以基本的WCF工作。 然后,他陷入了在UWP –