how to access a primitive return value as a result of making a function call in odata4j? - 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));

Related

C# to Vb.NET code convert

below code is c#
ctx.CreateStreamResponse(stream => new Session(_Sessions, stream).Process(),"video/mp4");
and i need to this code as VB.NET code. am converting as below
ctx.CreateStreamResponse(Function(stream) New Session(_Sessions, stream).Process(), "video/mp4")
But getting error
overload resolution failed because no accessible
"CreateStreamResponse" can be called with these arguments.
CreateStreamResponse needs 2 parameters
Stream (as my sample Function(stream) New Session(_Sessions, stream).Process())
content type (as my sample "video/mp4")
Anyone can help me, please
I believe the issue seems to be that the method which you pass into CreateStreamResponse should be a Sub not a Function. i.e:
ctx.CreateStreamResponse(Sub(stream) New Session(_Sessions, stream).Process(), "video/mp4")
CreateStreamResponse takes an Action(Of Stream) delegate as the first argument and a contentType of String as the second argument.
Thus you need to use Sub rather than a Function as in this case an Action delegate can only encapsulate methods that return void (sub procedures). Also, ensure that the Process method being invoked is also a Sub procedure.
If the problem persists then as suggested by Microsoft docs:
Review all the overloads for the method and determine which one you
want to call.
In your calling statement, make the data types of the arguments
match the data types of the parameters defined for the desired
overload. You might have to use the CType Function to convert one or
more data types to the defined types.
for more information see here

Get referring method in VB.net

I'm trying to get the referring method in vb.net.
e.g. I have 1 generic method (sendMail) that handle's emails, any other method can call this. I want sendMail to log an entry to the database when it sends an email. In this log i want the name of method that calls sendMail. I can do it by passing paramaters but I would like to know if sendMail can access the name of the method that calls it.
I found this article that works great in vs
Is it possible to get the referring method in VB.NET?
but unfortunately i'm working in a proprietary application and their IDE and the output I get from StackFrame is 'ExecuteAction at offset 1438 in file:line:column :0:0 '. I think it might be because the StackFrame used in example by Jon works in debug mode not release. (MSDN said something about debug mode but i'm not 100% sure here)
Is there another way of getting the calling method name?
Or am I using StackFrame incorrectly?
Cheers in advance.
dno
public string GetStackTrace()
{
StackTrace st = new StackTrace(true);
StackFrame[] frames = st.GetFrames();
return frames[1].GetMethod().Name.ToString();
}
give it a try:
this method will most likely return the name of its caller, with a few adjustment, you cant tweak it to nest back by increasing the index of the frames array.
good luck

WCF and out parameters

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.

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.

Why does a VB.Net function that returns string only actually return a single character?

I'm calling a function that returns a string, but it's only actually returning the first character of the string it's supposed to be returning.
Here's a sample piece of code to recreate the issue I'm experiencing:
Public Function GetSomeStringValue(Value as Integer) As String
... Code Goes here
Return Some_Multicharacter_string
End Function
The function call looks like:
SomeStringValue = GetSomeStringValue(Value)
Why is this not returning the entire string?
Note: this answer was originally written by the OP, Kibbee, as a self-answer. However, it was written in the body of the question, not as an actual separate answer. Since the OP has refused repeated requests by other users, including a moderator, to repost in accordance with site rules, I'm reposting it myself.
After trying a hundred different things, refactoring my code, stepping through the code in the debugger many times, and even having a co-worker look into the problem, I finally, in a flash of genius, discovered the answer.
At some point when I was refactoring the code, I changed the function to get rid of the Value parameter, leaving it as follows:
Public Function GetSomeStringValue() As String
... Code Goes here
Return Some_Multicharacter_String
End Function
However, I neglected to remove the parameter that I was passing in when calling the function:
SomeStringValue = GetSomeStringValue(Value)
The compiler didn't complain because it interpreted what I was doing as calling the function without brackets, which is a legacy feature from the VB6 days. Then, the Value parameter transformed into the array index of the string (aka character array) that was returned from the function.
So I removed the parameter, and everything worked fine:
SomeStringValue = GetSomeStringValue()
I'm posting this so that other people will recognize the problem when/if they ever encounter it, and are able to solve it much more quickly than I did. It took quite a while for me to solve, and I hope I can save others some time.