将调用WCF功能的c#DLL导入PowerShell

将调用WCF功能的c#DLL导入PowerShell,c#,wcf,powershell,svcutil.exe,powershell-module,C#,Wcf,Powershell,Svcutil.exe,Powershell Module,我有一个WCF服务,我使用以下命令为其生成了一个接口: svcutil.exe net.pipe://localhost/myService/MEX 我创建了一个新绑定,如下所示: var binding = new NetNamedPipeBinding(); binding.MaxBufferPoolSize = 104857600; binding.MaxBufferSize = 104857600; binding.MaxReceivedMessageSize = 104857600;

我有一个WCF服务,我使用以下命令为其生成了一个接口:

svcutil.exe net.pipe://localhost/myService/MEX
我创建了一个新绑定,如下所示:

var binding = new NetNamedPipeBinding();
binding.MaxBufferPoolSize = 104857600;
binding.MaxBufferSize = 104857600;
binding.MaxReceivedMessageSize = 104857600;
binding.ReaderQuotas.MaxArrayLength = 104857600;
binding.Security.Mode = NetNamedPipeSecurityMode.None;
binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
EndpointAddress endpoint = new EndpointAddress("net.pipe://localhost/myService/MEX");
IMyService service = ChannelFactory<IMyService>.CreateChannel(binding, endpoint);

对此有何想法?

您的服务URL以/MEX后缀结尾,这看起来有点奇怪。通常您只需要使用
net。pipe://localhost/myService
URL。

您的服务URL以/MEX后缀结尾,这看起来有点奇怪。通常您只需要使用
net。pipe://localhost/myService
URL.

我正在使用命名管道,我不想使用http获取元数据,因此使用mex。你可以读到区别是的,我明白了。但这正是svcutil.exe为您创建
iSeries设备
接口的用途。但是,当您创建一个频道时,您不需要“MEX”后缀。尝试将
EndpointAddress
构造函数更改为:
newendpointaddress(“net”)。pipe://localhost/myService“
,因为我相信您的主要服务(如
StartDisk
正在
网上收听。pipe://localhost/myService
endpoint)。即使您没有指定
serviceName
的值,我仍然认为您必须修复客户端代码才能从端点地址中删除
/MEX/
后缀。因为在服务器端有
selfHost.AddServiceEndpoint(typeof(T)、pipeBinding、new-StringBuilder().Append(serviceName.ToString())
,这意味着服务正在侦听地址,而没有
/MEX
(因为您在下面添加第二个端点时添加了它)。因此,尝试从客户端代码中删除
/MEX
,看看会发生什么。我使用的是命名管道,我不想使用http获取元数据,因此使用了MEX。你可以读到区别是的,我明白了。但这正是svcutil.exe为您创建
iSeries设备
接口的用途。但是,当您创建一个频道时,您不需要“MEX”后缀。尝试将
EndpointAddress
构造函数更改为:
newendpointaddress(“net”)。pipe://localhost/myService“
,因为我相信您的主要服务(如
StartDisk
正在
网上收听。pipe://localhost/myService
endpoint)。即使您没有指定
serviceName
的值,我仍然认为您必须修复客户端代码才能从端点地址中删除
/MEX/
后缀。因为在服务器端有
selfHost.AddServiceEndpoint(typeof(T)、pipeBinding、new-StringBuilder().Append(serviceName.ToString())
,这意味着服务正在侦听地址,而没有
/MEX
(因为您在下面添加第二个端点时添加了它)。因此,尝试从客户端代码中删除
/MEX
,看看会发生什么。
selfHost = new ServiceHost(reqsApi, pipeBaseAddress);
       var pipeBinding = new NetNamedPipeBinding();
       pipeBinding.MaxBufferPoolSize = 104857600;
       pipeBinding.MaxBufferSize = 104857600;
       pipeBinding.MaxReceivedMessageSize = 104857600;
       pipeBinding.ReaderQuotas.MaxArrayLength = 104857600;
       pipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
       pipeBinding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
       selfHost.AddServiceEndpoint(
            typeof(T),
            pipeBinding,
            new StringBuilder().Append(serviceName).ToString());
       ServiceMetadataBehavior SMB = new ServiceMetadataBehavior();
       selfHost.Description.Behaviors.Add(SMB);
       var behaviour = selfHost.Description.Behaviors.Find<ServiceBehaviorAttribute();
       behaviour.InstanceContextMode = InstanceContextMode.Single;
       var debug = selfHost.Description.Behaviors.Find<ServiceDebugBehavior();
       debug.IncludeExceptionDetailInFaults = true;
       var serviceEndpoint = selfHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                                         MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                                         new StringBuilder().Append(serviceName).Append("/mex").ToString());
       var behaviorExtension = new ProtoBuf.ServiceModel.ProtoBehaviorExtension();