Igliv
Igliv

Reputation: 214

Importing c# DLL that invokes WCF functionality to PowerShell

I have a WCF service for which I generated an interface using the following command:

svcutil.exe net.pipe://localhost/myService/MEX

I created a new binding as follows:

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);

When I tried using the module in PowerShell I got the following error:

Write-File : The message with Action 'http://tempuri.org/IMyService/StartDisk' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

At line:1 char:1

Write-File bla -verbose

~~~~~~~~~~~~~~~~~~~~~~~

CategoryInfo : NotSpecified: (:) [Write-File], ActionNotSupportedException

FullyQualifiedErrorId : System.ServiceModel.ActionNotSupportedException,DLM.Module.WriteFile

I'm using [ProtoContract] as the serialization protocol. I had to manually add it to the IMyService interface that was generated by the SvcUtil.exe command.

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();

Any thoughts on the issue?

Upvotes: 1

Views: 303

Answers (1)

Igor Labutin
Igor Labutin

Reputation: 1446

It looks a little bit strange that your service URL ends with /MEX suffix. Typically you would just use net.pipe://localhost/myService URL.

Upvotes: 0

Related Questions