WCF and out parameters - wcf

It seems there is restriction in having the number of out parameters in WCF. My service reference only downloads one out parameter.
Example: if the service has the following method:
void methodA(out string param1, out string param2)
then the service reference will only create
methodA(out string param1).
Anyone knows how to solve this?

I don't believe there's a limit to the number of out-parameters.
However, for a method that returns void, the first out-parameter actually becomes the return value of the method in the service reference due to a limitation in WSDL. So I would expect the signature of the method to become string methodA(out string param2).

Not sure of a correct fix, but I would return a list of items and not use out parameters in this situation.

Related

VB.net String Reverse Property different based on Env

I am debugging an application that runs on a server and users will access the application on another server. The application uses encryption and as part of the key, I am using the String.Reverse property.
Dim Mystring As String = "123abc"
Dim reverse = String.Format("{0},{1}", Mystring.Reverse)
The string reverse is different when I run it from one machine (RDP/Citrix Environment ASP.NET 4.6.1). The value is:
System.Linq.Enumerable+<ReverseIterator>d__a2`1[System.Char]
The same string, but ran from another machine (RPD non-Citrix Environment ASP.NET 4.5.2). The value of reverse is:
System.Linq.Enumerable+<ReverseIterator>d__73`1[System.Char]
Why are the values different in the different environments?
Look at this line first:
Dim reverse = String.Format("{0},{1}", Mystring.Reverse)
Specifically, this expression:
Mystring.Reverse
Reverse is a function, not a property, but it's missing the parentheses (). The trick here is the String.Format() method accepts the base Object type as an argument, and compiler is able to treat the MyString.Reverse expression as a delegate type that is convertible to object. The values you see in your output are the result of calling .ToString() on that function delegate. It's the type name for the function, rather than anything to do with the value of your MyString object. Since that type is dynamically and randomly generated at runtime, you'll see different values not only on different platforms, but different runs on the same computer.
In the VB6 era, it was normal to call methods without the parentheses. In the .Net world, always use parentheses when you call a method.
What you want is this:
Dim reverse As String = String.Format("{0},{1}", Mystring.Reverse())
Even here, you're missing the second argument to match the format string. I doubt you'll get the result you expect.
Finally, reversing a string as the key seems very wrong when it comes to encryption. You are using a real cyrptogrpahic algorithm from the System.Security.Cryptography library, right? Right!?
You are not outputting the value of the reversed String but the name of the type used to perform the reversal. That type is dynamically created and randomly named. The "d" in those two names means "dynamic" and the "a2" and "73" parts are random.
Basically, what you perceive to be an issue is not an issue. The problem is that you're not actually creating a String from the reversed output. You say "String.Reverse property but that is NOT a property. It is a method and it is not a member of the String class but rather an extension method on the IEnumerable(Of T) interface. You are treating your String as an enumerable list of Char values and reversing that. If you want a String from that then you need to create one, i.e.
MyReversedString = New String(Mystring.Reverse().ToArray())
That will push the contents of your iterator into an array and then create a new String object from that array.

Mocking void functions using EasyMock with dynamic behaviour

I need to mock a void function with EasyMock such that the first call returns an Exception, while the next succeeds.
For example:
this.myObject.move((String) EasyMock.anyObject());
EasyMock.expectLastCall().once().andThrow(new RetryableDependencyException());
EasyMock.expectLastCall().once();
But this is not working.
That's not going to work as the second expectLastCall() cannot find any call.
Have you tried this:
this.myObject.move((String) EasyMock.anyObject());
EasyMock.expectLastCall().once().andThrow(new RetryableDependencyException());
this.myObject.move((String) EasyMock.anyObject());
EasyMock.expectLastCall().once();
I know it's a bit verbose but it should get you sorted :)
The shortest is
myObject.move(anyString());
expectLastCall().andThrow(new RetryableDependencyException()).asStub();
which assumes that is doesn't matter if the method is called more than once after the exception. If it matters, it will be
myObject.move(anyString());
expectLastCall().andThrow(new RetryableDependencyException());
myObject.move(anyString());
Interesting facts:
You can chain andReturn
I highly suggest static imports to get a cleaner code
anyString is used to prevent the cast in String
once() is not required as it is the default
expectLastCall isn't required, calling the void method is enough to record a call without any side effect (like a throw)

how to access a primitive return value as a result of making a function call in odata4j?

The function shown below is a stub of a Service operation implemented in WCF Data Services, it accepts a string parameter and returns a string as well, how do I call this operation and read the returned string value back?, thank you.
[WebGet]
public string vMobile_FinishExport(string RouteCode);
I tried this
consumer.getEntities("vMobile_FinishExport?RouteCode='AA'").execute();
and it works without any problems, but I could'nt get through to read the returned string. The code samples I have gone through only shows reading entities and property values.
Thank you.
Use ODataConsumer#callFunction [1] to make a function call instead of getEntities.
Hope that helps,
- john
[1] http://odata4j.googlecode.com/hg-history/0.5/odata4j-core/doc/javadoc/org/odata4j/consumer/ODataConsumer.html#callFunction(java.lang.String)
Can you try below code , its working without any problem...
//printNameis the service operation method name
//"XYZ" is the passing parameter
OFunctionRequest<OObject> oFunctionRequest = oDataJerseyConsumer.callFunction("printName");
oFunctionRequest = oFunctionRequest.pString("printName", "XYZ");
Enumerable<OObject> s = oFunctionRequest.execute();
System.out.println(s.elementAt(0));

changing the parameter value in IparameterInspector WCF RESTful

I am trying to change the value of the parameter in IParameterInspector while doing the validation. The parameters that are string, works fine. But I need int as parameters. and if the parameter is not supplied in the RESTful call, I need to default it.
If the url does not contain anything for int parameter, it fails. However, in the same case of string parameter, if its not supplied, it takes the default values.
I use querystring format for passing the parameters. and I am just trying to run it on the browser.
Is there any way for this to work? or do I need to make all the parameters as string.
Thanks in Advance!
You need to make the parameters string. This will be fixed in the next version of the WCF Web APIS http://wcf.codeplex.com

dynamic content type

i want to make a single wcf rest function which can return any content type (text-html / applicaiton-javascript and even gif .
what should be the signature of the function ( the return type )
what should be the format of the service ?like [WebGet(ResponseFormat = WebMessageFormat.Json)]
P.S: i cant make any new method due to the format of my javascript calls and due to the limitation on wcf rest since it doesnot differentiate b/w calls based on the parameter part(after the ? ) of the query string .
thanks
You can use the return type Stream.