Reputation: 2436
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/">
<soap:Body>
<SubmitiPhoneObject xmlns="http://www.myServer.com/iPhoneService/">
<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!
Upvotes: 1
Views: 2388
Reputation: 2436
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.
Upvotes: 2
Reputation: 70997
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.
Upvotes: 0
Reputation: 75058
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/
Upvotes: 1
Reputation: 161773
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.
Upvotes: 1
Reputation: 11606
This is a waaaay too general question.
You say you can't submit from iPhone to .NET. But can you submit from elsewhere?
If you can't, then iPhone falls out of the equation, and this is a .NET issue.
If you can, then check what the difference is between the successful request and the one made by an iPhone. If the iPhone produces something that
isn't a valid SOAP request:
.NET falls out of the equation, and this is a problem with your XML serialization.
is a valid SOAP request, but isn't getting recognized by the web service:
In this case you have two options:
I suggest doing both.
If your request is simple, then just storing it as a string on the iPhone might be a viable option.
Upvotes: 0
Reputation: 15180
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!
Upvotes: 1