Dailycode.info

Short solution for short problems

iOS : passing < (smaller then or less then) as SOAP parameter

I was passing queries from the client to the server to fill up objects. In the queries, sometimes the < sing appeared. when it did, the query string parameter did not reached the server. So I found this solution on stackoverflow. 

Just embed the querystring in CDATA tag like this:

NSString * parsedQuery = [NSString stringWithFormat:@"<![CDATA[\n%@\n]]>",query];

 

So now you can pass a query like this to your web service:


NSString * query = [NSStringstringWithFormat:@"SELECT * FROM PlanOrders AS pl  LEFT OUTER JOIN ERP_Customers AS cu ON pl.Client = cu.Client AND pl.CustomerID = cu.Customer  inner join Orders o on pl.SalesOrder = o.SalesOrder and pl.Client = o.Client and pl.Plant = o.Plant  WHERE pl.Client = '%@' AND pl.Plant = '%@' AND pl.PlanDate IS NOT NULL AND pl.PlanDate >= '%@'  AND pl.PlanDate < dateadd(day,1,'%@') AND (pl.PlanStatus < 100)  ORDER BY pl.PlanDate",store.Client, store.Plant,[formatter stringFromDate:self.dateFrom],[formatter stringFromDate:self.dateTo]];


NSString * parsedQuery = [NSString stringWithFormat:@"<![CDATA[\n%@\n]]>",query];

[service ExecuteQueryForiOS:self action:@selector(getPlanning:) commandText:parsedQuery];


.Net Self Tracking Entities and JSON

I know this is not the ideal situation, better to use POCO's or simple objects. But when you already have a large structure in place using these self tracking entities, it can be usefull to do this. In my case we had webservices build for .Net client applications. Now we want to reuse this architecture and consume it on IPAD and IPHONE. Can this work? Yes offcourse. First I tried with SOAP, which works well, but there were 3 problems. First I was relying on a object generator tool of SUDZC, second SOAP is taking more data then JSON, third, iOS doesn't support nillable and the generator converted it into simple types. So now I decided to use JSON, use my own objects and reuse the webservices. 

This involved making a new service layer the consumes the same process layer as my .Net WCF services.

But you will notice that when you try to pass a self tracking entity in JSON format, the webservice will crash. 

The solution to this was:

Set the IsReference flag to false, and remove the DataMember attribute from the ChangeTracker.

//[DataMember]

public ObjectChangeTracker ChangeTracker

and

[DataContract(IsReference = false)]

public partial class GP_MES_Clients: IObjectWithChangeTracker, INotifyPropertyChanged

After this all is changed, you can consume this service in your iOS application!