Using IOperationBehavior to supply a WCF parameter -


This is my first step in the world of stackoverflow, so I apologize if anything cocks up.

I am trying to create a WCF operation in which there is a parameter that is not in the external world but rather in the auto function.

Then the world sees: int add (int a, int b)

but it is implemented: int add (object) Context, int a, int b)

Then, the context is provided by the system in run-time. For example, I am working completely artificial, but some such Imagine the thing that I see in a real world scenario.

I am able to get close, but not completely there.

At first, I created an easy way and wrote an application to confirm that it works. It happens. It gives A + B and writes the reference as a string for my debug. Yay

  [OperationContract] int ed (object context, int a, int b);  

I have written the following code:

  Public class SupplyContextAttribute: Properties, IOperationBehavior {Public Null Valid (OperationDescription OperationDescription) {if (OperationDescription.Messages. Anyone (M => M. Body. Pars. First (.name == "Context")) Throw New Fault Depth ("Parameter Reference is Unavailable. ');} Public Zero ApplyDispatchBehavior (OperationDescription OperationDescription, DispatchOperation DispatchOperation) {dispatchOperation.Invoker = New SupplyContextInvoker (dispatchOperation.Invoker);} Public Zero ApplyClientBehavior (OperationDescription operationDescription, ClientOperation clientOperati On} {} Public Zero AddBindingParameters (OperationDescription operationDescription, BindingParameterCollection bindingParameters) {// Inbound Message OperationDescription.Messages [0] Remove 'Reference' Parameters from Body.Parts.RemoveAt (0);}} Public Square SupplyContextInvoker: IOperationInvoker { Read Only IOperationInvoker _invoker; Public. } Public object [] AllocateInputs () {return_invoker.AllocateInputs (). Skip (1) .ToArray (); } Private Object [] Introduction to Ttex (Object [] Input] {New [] {"MyContext"} Return. Concrete (input) .oere (); } Invoke the public object (object example, object [] input, out object [] output) {return_invoker.Invoke (example, introduction of introduction (output), out output); } Public IAsyncResult InvokeBegin (Commodity Parable, Object [] Inputs, AsyncCallback Callback, Object State) {Return _invoker.InvokeBegin (Example, IntroduceContext (Inputs), Callback, State); } Public Object InvokeEnd (Object Example, Out Object [] Output, IAsyncResult Results) {Return _invoker.InvokeEnd (Example, Output Out, Results); } Public Bull ISCnellus ({Return_Invoire.ISISCNAS;}}}  

And my WCF operations are still looking like this:

  [OperationContract, SupplyContext] integer In the context of the object (in the context of the object, an int, int b);  

My updated reference no longer reflects the 'reference' parameter, what exactly i want.

The problem is that whenever I run the code, it throws the last AllocateInputs and then an index, array of I was out of umma. Error anywhere in the WCF group.

I have tried other things, and I think I can successfully change the type of parameter and change its name And I can work my code, but at the moment I remove the parameter.

Can someone give me some ideas to do this work (or it can be done at all).

Good, I I have put it on my own. There is an index property in MessagePartDescription. I just need to resynch these values. Public Zero AddBindingParameters (OperationDescription operationDescription, BindingParameterCollection bindingParameters) {var parts = operationDescription. Messages [0] .Body.Parts. Parts.RemoveAt (0); For (Int i = 0; I & lt; Parts.Count; I ++) Parts [I] Index = I; }


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -