dynamic content type - wcf

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.

Related

How can I return JSONP in RestXQ (using eXist-db)?

I cannot figure out how to return JSONP in RestXQ. After adding
let $x := util:declare-option("exist:serialize", fn:concat("method=json jsonp=",request:get-parameter("callback", "callback")))
to the function, I get the error message:
err:XPTY0004:It is a type error if, during the static analysis phase, an expression is found to have a static type that is not appropriate for the context in which the expression occurs, or during the dynamic evaluation phase, the dynamic type of a value does not match a required type as specified by the matching rules in 2.5.4 SequenceType Matching.
The beginning of the GET function is:
declare
%rest:GET
%rest:path("/demo/contacts/submit")
%rest:query-param("email", "{$email}", '')
%rest:query-param("nomail", "{$nomail}", 0)
%rest:produces("application/javascript")
%output:media-type("application/javascript")
%output:method("json")
function contacts:submit($email as xs:string*, $nomail as xs:integer*)
{
try
{
let $x := util:declare-option("exist:serialize", fn:concat("method=json jsonp=",request:get-parameter("callback", "callback")))
As discussed on the eXist-open mailing list (I'd suggest joining!), the request module's get-parameter() function is not available inside a RestXQ function. Instead, you can get your callback parameter via the %rest:query-param annotation. Add %rest:query-param("callback", "{$callback}", '') to your contacts:submit() function, and I think you'll be a step closer.
#joewiz is correct. Your initial problem is related to the use of eXist request module from RESTXQ, which is unsupported.
Also, RESTXQ does not currently support JSONP serialization. If you want to use JSONP serialization, your best bet at the moment is to manage the serialization to JSON yourself, perhaps using the xqjson library or similar and then wrapping the result in a JSON function using concat or similar.

oData operation consumption with objective-C

I have a really simple WCF service operation GetCurrentBalance. It returns a decimal.
I also have the odatagen generated entity files included in the project, which contains an implementation of the GetCurrentBalance operation returning a string. Calling this method returns me an XML string with the desired value in it.
I also tried using executeServiceOperation method in the generated class and pass in the operation name as a parameter, the returned value again is the same XML string.
Is there a way to extract this value? Or do I have to write a custom parser for it?
Thanks in advance.
Without further informations, if the returned value is a formatted XML string you may try extracting the value using XPath queries, have a look at this to get you started

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

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.