gpt4 book ai didi

wcf - 使用 Unity 找不到命名空间 "ServiceModel"

转载 作者:行者123 更新时间:2023-12-04 19:49:16 24 4
gpt4 key购买 nike

我想在我的 Unity 应用程序中使用 WCF 服务(通过命名管道)。因此,我包括以下两个命名空间:

using System.ServiceModel;
using System.ServiceModel.Channels;

在 Unity 中运行我的项目后,这会导致以下两个错误:
Assets/Scripts/program.cs(4,14): error CS0234: The type or namespace name ServiceModel' does not exist in the namespaceSystem'. Are you missing an assembly reference?

Assets/Scripts/program.cs(5,14): error CS0234: The type or namespace name ServiceModel' does not exist in the namespaceSystem'. Are you missing an assembly reference?

接下来,我将 Unity 脚本编辑器从 MonoDevelop 更改为 Visual Studio 2013。在 Visual Studio 中打开相同的脚本后,术语“ServiceModel”带有下划线(锯齿形红线)并且 Visual Studio 表示此命名空间不可用。手动添加“System.ServiceModel”后,那些红线消失了。但是当我从 Unity 运行它时,我再次遇到相同的错误。此外,当我重新启动 Unity 并返回到 Visual Studio 中的该脚本时,我又必须手动添加“System.ServiceModel”。

我希望你明白我的意思。
如何永久包含“System.ServiceModel”和“System.ServiceModel.Channels”?

请注意,我目前使用的是 Visual Studio Pro 和 Unity Pro 的试用版。这可能是个问题吗?

最佳答案

谢谢!我只是将文件 System.ServiceModel.dll 复制到我新创建的 Assets\Plugin 目录中。错误消失了:-)。但是,我现在遇到了另一个错误。

使用以下命令,我想创建一个 NamedPipe 类型的代理。

ChannelFactory<ClassName> pipeFactory = new ChannelFactory<ClassName>(new NetNamedPipeBinding(),new EndpointAddress("net.pipe://localhost/PipeReverse"));               
ClassName pipeProxy = pipeFactory.CreateChannel();

当我运行我的代码时,我收到以下错误:

InvalidOperationException: Channel type IDuplexSessionChannel is not supported. System.ServiceModel.Channels.NamedPipeChannelFactory1[System.ServiceModel.Channels.IDuplexSessionChannel].OnCreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via)
System.ServiceModel.Channels.ChannelFactoryBase
1[System.ServiceModel.Channels.IDuplexSessionChannel].CreateChannel (System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) System.ServiceModel.ClientRuntimeChannel..ctor (System.ServiceModel.Dispatcher.ClientRuntime runtime, System.ServiceModel.Description.ContractDescription contract, TimeSpan openTimeout, TimeSpan closeTimeout, IChannel contextChannel, IChannelFactory factory, System.ServiceModel.Channels.MessageVersion messageVersion, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) System.ServiceModel.ClientRuntimeChannel..ctor (System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.ChannelFactory channelFactory, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) __clientproxy_ClassName..ctor (System.ServiceModel.Description.ServiceEndpoint , System.ServiceModel.ChannelFactory , System.ServiceModel.EndpointAddress , System.Uri ) System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:513) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:519) System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:528) System.Activator.CreateInstance (System.Type type, BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/Activator.cs:338) System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/Activator.cs:268) System.Activator.CreateInstance (System.Type type, System.Object[] args) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/Activator.cs:263) System.ServiceModel.ChannelFactory1[ClassName].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via)
System.ServiceModel.ChannelFactory
1[ClassName].CreateChannel (System.ServiceModel.EndpointAddress address) System.ServiceModel.ChannelFactory`1[ClassName].CreateChannel () IDL_vehicle.Start () (at Assets/Scripts/IDL_vehicle.cs:30)

关于wcf - 使用 Unity 找不到命名空间 "ServiceModel",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24040904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com