Hi,
I am trying to connect to an existing WCF service. I am getting the following exception when trying to call wcf service. ProtectionLevel is EncryptAndSign for all methods.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The request message must be protected. This is required by an operation of the contract ('IService','http://tempuri.org/'). The protection must be provided by the binding ('WSHttpBinding','http://tempuri.org/'). at System.ServiceModel.Dispatcher.SecurityValidationBehavior.ContractProtectionRequirementsRule.ValidateBindingProtectionCapability(Binding binding, ContractDescription contract, ProtectionLevel request, ProtectionLevel response) at System.ServiceModel.Dispatcher.SecurityValidationBehavior.ValidateNoSecurityBinding(Binding binding, ContractDescription contract) at System.ServiceModel.Dispatcher.SecurityValidationBehavior.ValidateBinding(Binding binding, ContractDescription contract, SecurityBindingElement& securityBindingElement) at System.ServiceModel.Dispatcher.SecurityValidationBehavior.System.ServiceModel.Description.IEndpointBehavior.Validate(ServiceEndpoint serviceEndpoint) at System.ServiceModel.Description.ServiceEndpoint.Validate(Boolean runOperationValidators, Boolean isForService) at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose) at System.ServiceModel.ChannelFactory.CreateFactory() at System.ServiceModel.ChannelFactory.OnOpening() at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ChannelFactory.EnsureOpened() at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ChannelFactory`1.CreateChannel() at System.ServiceModel.ClientBase`1.CreateChannel() at System.ServiceModel.ClientBase`1.CreateChannelInternal() at System.ServiceModel.ClientBase`1.get_Channel() at ExternalService.Client.Create() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Dynamics.AX.ManagedInterop.ClrBridgeImpl.InvokeClrInstanceMethod(ClrBridgeImpl* , ObjectWrapper* objectWrapper, Char* pszMethodName, Int32 argsLength, ObjectWrapper** arguments, Boolean* argsAreByRef, Boolean* isException)
Example
static void Job1(Args _args) { #define.Type_ServiceClient('ExternalService.Client') ExternalService.Client serviceClient; System.Exception exception; System.Type type; ; try { type = CLRInterop::getType(#Type_ServiceClient); serviceClient = AifUtil::createServiceClient(type); serviceClient.Create(); } catch(Exception::CLRError) { exception = CLRInterop::getLastException(); while(exception) { info(CLRInterop::getAnyTypeForObject(exception.ToString())); exception = exception.get_InnerException(); } } }
Can someone help to resolve the issue.
Thanks in advance