我想在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”带下划线(Zigzag red line),Visual Studio表示此命名空间不可用。手动添加“System.ServiceModel”后,这些红线消失。但是当我从Unity运行它时,我再次遇到同样的错误。此外,当我重新启动Unity并在Visual Studio中返回该脚本时,我必须再次手动添加“System.ServiceModel”。
我希望你理解我的意思。 如何永久包含“System.ServiceModel”和“System.ServiceModel.Channels”?
注意,我目前正在使用Visual Studio Pro和Unity Pro的试用版。这可能是一个问题吗?
答案 0 :(得分:0)
谢谢!我刚刚将文件 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:不支持通道类型IDuplexSessionChannel。 System.ServiceModel.Channels.NamedPipeChannelFactory
1[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 /类/ corlib /的System.Reflection / MonoMethod.cs:222) Rethrow as TargetInvocationException:调用目标抛出了异常。 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 /类/ 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 /类/ corlib /的System.Reflection / MonoMethod.cs:513) Rethrow as TargetInvocationException:调用目标抛出了异常。 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 /类/ 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类型,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()(在Assets / Scripts / IDL_vehicle.cs:30)