Changing response serializer for a particular call inside AFHTTPSessionManager - objective-c

I am subclassing AFHTTPSessionManager to make different POST requests to one server. All responses from the server are returned in JSON format, so I set response serializer for AFHTTPSessionManager to AFJSONResponseSerializer. But for one POST request I need to change response serializer to some other (leaving all other to use AFJSONResponseSerializer). Is is possible to do that?

Try AFCompoundResponseSerializer, you may add different serializers in it.

Related

Mule ESB Flow to pass parameters in Calling SOAP Webservice

I have created on flow in MuleESB which is calling a web-service without any parameter just sending it username, password and token in a property and it is working fine.
But the second API I want to post some parameters while calling soap request but I don't know how to use it I tried to pass through set payload but no response.
use Webservice consumer and add a transform message component beofre it. by doing so you can automatically map all the parameters which are required by the SOAP webservice, as datasence will automaticall download the meta deta of the service using the WSDL file.
Make sure you select application/xml as content type in Postman or SOAP UI and select POST.
Use CXF and select Operation as Proxy Service ,Provide details. Selct and provode (WSDL,MTOM enabled,SOAP Headers ,SOAP 1.2)
Make sure you posting XML request "POST" method in allowed methods.
Use 2 transformers. XML to DOM and DOM to XML.
Log the request using
#[message.payloadAs(java.lang.String)]
Use a groovy script transformer to retreive the entire payload.
def userSoapRequest = new XmlSlurper().parseText(payload);
def userId = userSoapRequest.userId.text();
message.setInvocationProperty('userId', userId);
6.Retrieve userId like above and similarly for all the elements.
7.Process them as you want.
Hope this helps

Exclude some parameters with POST request on RestKit

I've just integrated RestKit with a Mac application for communicating with a web service. After much confusion, I have successfully got requests and responses working using it.
The problem I am now finding is that when I want to make a POST request.
I have created a RKRequestDescriptor with a mapping for a whole number of properties and all of the properties are being sent as parameters for the query. I want a way of dynamically changing the parameters that are sent, for example not sending some parameters where the property is nil.
Is this possible as part of the built-in functionality of RestKit? And if so, how?
You would need to use RestKit's Dynamic mapping class to handle mapping at run time.
Dynamic Object Mapping
RestKit supports such use cases via the RKDynamicMapping class.
RKDynamicMapping is a sibling class to RKObjectMapping and can be
added to RKRequestDescriptor and RKResponseDescriptor objects and used
to configure RKMappingOperation instances. RKDynamicMapping allows you
to hook into the mapping process and determine an appropriate concrete
RKObjectMapping to use on a per-object basis.
Or you could not use RestKit and set the POST body yourself. Create the required dictionary by adding only required parameters. Serialize this object with help of NSJSONSerialization and set this NSData object as HTTP Body in the request instance.

How to pass object to RESTful Service with GET request?

I have seen some posts in stackoverflow saying "sending list of items in the GET Method, is NOT allowed. It has to be accomplished via POST method only"
My code looks like
[OperationContract]
[WebGet(UriTemplate = "Employee/{emp}",RequestFormat=WebMessageFormat.Json)]
Employee GetEmpDetails(string emp);
and my input json object will be "{'id':1,'name':'test',....}
Is there any alternative way of achieving this issue.
Thanks
It is possible to send list of items with GET, it's just that out of the box only primitive values are supported. String values work just fine, but if you want to pass a complex object, you need to create a custom QueryStringConverter. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx explains how this can be done.
If you make your service RESTful you will most probably use HTTP PUT for Add method and HTTP POST for Update method. It is absolutely ok to pass object to these methods because objet will be part of HTTP request's body, not part of URI. URI is important for HTTP GET requests. HTTP GET requests should be only for data retrieval not for data modification.
You are mixing up HTTP GET/POST/... requests and REST GET/POST/PUT/DELETE/...
When you wanna request something RESTfully - you do a GET request. In your case I think it should look like
employee/{id}
or
employee/{name}
Please also note that usage of lowercase in the URI is preferable.
If you need multiple GET criteria, I think it could look like:
employee/id/{id}/name/{name}

Use XmlSerializer on request and DataContractSerializer on response?

Is it possible to receive a request with attributes and use the XmlSerializer to deserialize it and send a response back with just elements using the DataContractSerializer?
Also, if you receive a request with attributes, must you use the XmlSerializer to deserialize the content?
For the second question: if you have attributes, then you need to use the XmlSerializer - the DataContractSerializer doesn't support them.
For the first question: yes, it's possible. No, it's not easy. The selection of the serializer is done at the operation formatter level. WCF allows you to change the serializer per operation by using the [XmlSerializerFormat] or [DataContractFormat] (which is default), but that will bind the serializer to both request and responses.
If you really, really want to do it, you can create your own formatter (replace it using some operation behavior), then in that formatter you can choose how you serialize / deserialize the inputs / outputs (you can even use different serializers for each parameter), but you'll need to create one formatter, which isn't something too easy to do.
I've written some posts about message formatters and replacing serializers in Silverlight which can give you a hint on how to start about it. But if you can live with XmlSerializer only, that'll be a lot easier.

Best way to support "application/x-www-form-urlencoded" post data with WCF?

I'm building a WCF service based on a W3C specification which defines a RESTful web service endpoint that accepts "application/x-www-form-urlencoded" post data. WCF doesn't support this type of message encoding by default and I have found a number of different examples of creating a contract that looks like this:
XElement Query_Post(Stream postData);
And then within the implementation decoding the postData stream using the HttpUtility.ParseQueryString method.
Does anyone know of a more strongly typed way of supporting "application/x-www-form-urlencoded" in WCF?
I would like my operation contract to be:
XElement Query_Post(string query, string [] params);
The best way is to use Stream like Raw HTTP POST with WCF or what you are saying.
The reason is because WCF abstracts all the communication-level physical layout stuff out from the service code. Ideally, you would want to make a service that could turn into SOAP or REST just by flipping the switch.
To support it natively, you probably have to extend WebHttpBinding or make your own binding and implement custom encoder. This is symmetric to the output like the linked post says. You have to twist its arms to get WCF to output non-XML/JSON stuff.
The WCF REST Contrib library enables this functionality:
https://github.com/mikeobrien/WcfRestContrib
It includes a POX formatter and form url encoded formatter and allows you to easily create your own. Formatters are mapped to mime types and automatically selected to serialize/deserialize the entity body based on the content type and accept headers.