Dailycode.info

Short solution for short problems

iOS and SUDZC: using objects from multiple (different) namespaces.

Tackled another problem using SUDZC and found a generic solution for this. 

I was passing objects that were in a different namespace then my function was. By default the prefix looked like this: <a:MyObject/>. But then the a prefix was pointing to another namespace. So now I had to make sure that I could tell my objects which namespace to use. I added a property xmlPrefix to the objects that were used in a different namespace. By default it has @"a" in it, but when i pass these objects in another namespace, I change it to @"b". Then I add this extra namespace in the SOAP request and it works. It took a while to find, but now this problem will not hold me back any more in the future.

The prefix look like this:

 

NSString* const SOAP_FUNCTION_SYS_PREFIX = @"xmlns:b=\"http://schemas.datacontract.org/2004/07/GalvaSFIMobileEntities.SYS\"";

 

In the object I added the xmlPrefix property:

 

@property (retain, nonatomic) NSString * xmlPrefix;

 

Then I set in by default to @"a" in the super init:

 

- (id) init

{

    if(self = [super init])

    {

        self.BlockCode = nil;

        ...

        self.xmlPrefix=@"a";

        

    }

    returnself;

}

 

Next I change it when the objects are used in soap request with multiple custom namespaces:

 

OrderBlockCodes * code = ((OrderBlockCodes *)[self.orderBlockCodesArrayobjectAtIndex: indexPath.row]);

code.xmlPrefix=@"b";

[self.selectedBlockCodes addObject: code];

 

So finally the XML looks like this:

 <?xml version="1.0" encoding="utf-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:tem="http://tempuri.org/" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/"  xmlns:b="http://schemas.datacontract.org/2004/07/MobileEntities.SYS" >

<soapenv:Body>

<tem:BlockOrderPosition>

<tem:lOrder>356009200</tem:lOrder>

<tem:sOrderPos>30</tem:sOrderPos>

<tem:bBlock>0</tem:bBlock>

<tem:bFullOrder>0</tem:bFullOrder>

<tem:remark>Jmblkjjtlilu heilig kuub. Iulh</tem:remark>

<tem:codesToBlock><b:OrderBlockCodes><b:BlockCode>A1</b:BlockCode><b:BlockCodeClass1>P</b:BlockCodeClass1><b:BlockCodeDescription>Openings / Gaten </b:BlockCodeDescription><b:BlockCodeGroup>A</b:BlockCodeGroup><ChangeTracker><b:State>Unchanged</b:State></ChangeTracker><b:Created>2009-05-15T00:00:00.000</b:Created><b:CreatedBy>mderaeve</b:CreatedBy><b:ModifiedBy></b:ModifiedBy><b:UpdCount>1</b:UpdCount></b:OrderBlockCodes>...


Serialized SOAP has some records empty and set to reference another.

Since I have a .Net back end WCF service and a front end iOS consumer, I have tackled several new challenges and learned a lot of what SOAP is all about. The next strange thing I encountered and it took me an hour or 2 to find out the solution was:

On my iOS client I suddenly got 15 records, where 7 of then were just empty records. I could not find the reason, on the server SQL all records were there and all records were filled in and unique. Then I took a closer look to the incoming SOAP message and found out that there were 7 records that looked like this:

<a:GP_MES_SetOrderPosReadyHistory xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i1"/>

So no contents only an empty xml tag with at the end z:Ref="i1". Soon I discovered that it was referencing a record that was found earlier in the XML with the same keys. So strange, because the rest of the item was different. At this website I found out that settings the IsReference property on the data contract creates this behavior. So one thing you could do is to set it to false. In my case the data contracts were generated by self tracking entities. So I discovered that I had to adjust the key fields of the entities. In my case it was on a view and the key fields were not unique for each records. So I added an extra field to the key fields and now it works perfect.