views:

1419

answers:

6

My iPhone application needs to submit an object to an already existing .NET SOAP Web Service so it can be saved to a database server. I figured the easiest way to go about this would be building an XML representation of the object and passing it to the web service. However, this doesn’t seem to be working. If the XML is more than one level deep the web service method appears to not be getting called (The web service method writes an entry to the event log when it is called).

For example if the XML is:

<Name>Jim</Name>

The web service method gets called and there is an entry in the event log on the web server.

If the XML is:

<Person><Name>Jim</Name></Person>

The web service method is not called (there is no entry in the event log).

Here is the web service method definition:

public string SubmitiPhoneObject(string theObjectAsXml) {
    WriteToEventLog("Begin Service.SubmitiPhoneObject");
    // Do some work…
}

And here is the SOAP request I am submitting from the iPhone:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
<soap:Body>
    <SubmitiPhoneObject xmlns="http://www.myServer.com/iPhoneService/"&gt;
        <theObjectAsXml>
            <TheObject>
                <PersonID>5263</PersonID>
                <DepartmentID>379</DepartmentID>
            </TheObject>
        </theObjectAsXml>
    </SubmitiPhoneObject>
</soap:Body>

Anyone have any idea why the web service method isn’t getting called? Anyone have better/easier suggestions on how to submit an object to a web service from an iPhone application?

Thanks!

+1  A: 

Full SOAP processing is usually considered to be a little more resource-intensive than ideal for the iPhone and other mobile devices so your approach of directly generating the XML you need is probably a good one.

For debugging this I'd recommend grabbing the response XML you receive back from the server when you submit this request. That response should give you more information about what was done on the server and any errors that were encountered. Hope this helps!

Adam Alexander
That is one of the problems, the web method appears to never get called and there is no response XML back from the web service.
Billy
A: 
Jaka Jančar
+1  A: 

You should use soapUI to talk to build messages to send to your servce. You will then know what format to send the messages in.

John Saunders
A: 

If you must use SOAP (and I would push really hard to use something simpler), then consider using WSDL2ObjC to generate the communications code instead of rolling it manually:

http://code.google.com/p/wsdl2objc/

Kendall Helmstetter Gelner
A: 

The objective-c wrapper given here works great when trying to send data to a web-service. If you want to submit the XML to the web-service, read the XML's contents into an NSData object and pass that NSData as the body of your HTTP request. This works as expected.

lostInTransit
+1  A: 

Thanks for the answers, I ended up encoding the XML string before passing it up and decoding it on the server.

On the iPhone I used:

[xml stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]

to do the encoding.

And on the server I used

Server.UrlDecode

to do the decoding. Seems to be working so far.

Billy