Solved

SOAP web service call with parameters is failing

Posted on 2013-12-10
17
801 Views
1 Endorsement
Last Modified: 2016-02-26
I have a very simple .net web service which accepts a string parameter and returns the same string converted to uppercase.

The web service works just fine when called from an ASP.NET web page.

However, when I call it from an IOS app the parameter sent in is not received, even though I have verified that the values are sent in the SOAP message as can be seen below:

<soap12:Body>
<TestReturnVal xmlns="http://tempuri.org/" /><pName>brian</pName>
</soap12:Body>

Open in new window


The .NET function that's being called is:
<WebMethod()>_
Public Function TestReturnVal (ByVal pName As String) As String

Dim nUpper As String = UCase(pName)
Return "RETURN TEXT: " & nUpper & ": SHOULD BE HERE"

End Function

Open in new window


When I get the returned stream from the above function, I only get the hard-coded text and not the value of the variable.

<TestReturnValResult>RETURN TEXT: : SHOULD BE HERE</TestReturnValResult>

Open in new window


Any help would be extremely helpful, I'm completely stumped on this :(
1
Comment
Question by:BrianFord
  • 9
  • 5
  • 3
17 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39711333
I have very little experience with iOS, but I would look for an HTTP debugger, so that you can see the difference between the web application and the iOS application.

Quick search:

PonyDebugger: Remote Debugging Tools for Native iOS Apps
http://corner.squareup.com/2012/08/ponydebugger-remote-debugging.html
0
 

Author Comment

by:BrianFord
ID: 39711341
Thanks I'll take a look at that, the strange thing is that if I call a web service that does not expect any parameter (just returns a string for example) everything works perfectly :(
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39711351
How did you generate this SOAP message?

<soap12:Body>
     <TestReturnVal xmlns="http://tempuri.org/" /><pName>brian</pName>
</soap12:Body>
0
 

Author Comment

by:BrianFord
ID: 39711398
The above is just a snip of the complete message, but it is taken from the service definition (WSDL) and is basically hard-coded in the app.

The complete iOS code for the request is below:

NSString *soapMsg = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                         "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                         "<soap12:Body>"
                         "<TestReturnVal xmlns=\"http://tempuri.org/\" />"
                         "<pName>%@</pName>"
                         "</soap12:Body>"
                         "</soap12:Envelope>", @"brian"];

Open in new window

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 300 total points
ID: 39711408
Another approach would be to use Soap UI to debug the SOAP messages from the web application where it works, so that you can make sure that you have the messages exactly as required.

‘’SoapUI free tool to help debug the Web Services’’
soapUI-in-the-news/soapui-free-tool-for-to-help-debug-the-web-services.html
0
 

Author Comment

by:BrianFord
ID: 39711717
I'll take a look at that also, but I know the message is in the correct format as it's taken directly from the WebService definition which is shown below:

The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.

POST /tagScan.asmx HTTP/1.1
Host: <snip>
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/webservices/checkGP"

<?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>
    <checkGP xmlns="http://tempuri.org/webservices">
      <tagNum>string</tagNum>
      <qty>string</qty>
    </checkGP>
  </soap:Body>
</soap:Envelope>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39711777
What are you using on the iOS side to send the SOAP message?
0
 

Author Comment

by:BrianFord
ID: 39711801
It's basically just an HTTP Request
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 39711997
No, I meant what are you using to develop the software (design platform, version, ...)?
0
 

Author Comment

by:BrianFord
ID: 39712246
oh sorry, I'm using XCode V5.0.2 on a Mac
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 200 total points
ID: 39712959
but I know the message is in the correct format as it's taken directly from the WebService definition which is shown below
Did you not post what you meant on your previous comment http:#a39711717 ? What you have posted appears to be some totally different to the other snippets/code that you have posted, as it deals with the "checkGP" service with parameters of "tagNum" and "qty", whereas your question is about "TestRuternVal" and "pName".


In any case, I'm 99% sure that your message is NOT in the correct format. Try the below code in your iOS app...
NSString *soapMsg = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                         "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                         "<soap12:Body>"
                         "<TestReturnVal xmlns=\"http://tempuri.org/\">"
                         "<pName>%@</pName>"
                         "</TestReturnVal>"
                         "</soap12:Body>"
                         "</soap12:Envelope>", @"brian"];

Open in new window

The change that I have made, is that now the "pName" element is actually a child of the "TestReturnVal" element. The way you had it, had "pName" outside of "TestReturnVal".
0
 

Author Comment

by:BrianFord
ID: 39713006
Thanks,

You are correct I posted the wrong code, I've got 2 apps having this issue and the last post was from the 2nd, sorry about that :)

but as it's the same issue with both your solution may work anyway, so I'll give it a try later and let you know,

thanks again
0
 

Author Closing Comment

by:BrianFord
ID: 39713192
Thanks everyone for your help, after much trial and error and then finally downloading SOAPUI it eventually works.

It was a combination of getting the correct XML using SOAPUI and then changing the syntax in XCODE to get the call in the correct format.

Thanks again :)
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39713195
Out of interest, can you post the final code that you needed to get it to work?
0
 

Author Comment

by:BrianFord
ID: 39713199
Certainly, here it is:

NSString *soapMsg = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                         "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
                         "<soap12:Body>"
                         "<TestReturnVal xmlns=\"http://tempuri.org/\">"
                         "<pName>%@</pName>"
                         "</TestReturnVal>"
                         "</soap12:Body>"
                         "</soap12:Envelope>", @"brian"];

Open in new window

0
 
LVL 35

Expert Comment

by:mccarl
ID: 39713271
Hmmm, it is exactly what I posted above? Am I missing something here?

Why then the need for "much trial and error" and "getting the correct XML using SOAPUI" if I had already given you the correct XML?
0
 

Author Comment

by:BrianFord
ID: 39713848
It was a bit strange and possibly just an Xcode parsing issue but initially it didn't work. When pasting in your code above XCode complained about syntax errors and the build failed.

In previous code examples I had got from the web and books, each line had either '\n' or '/\' in order for it to parse correctly, I put those back in and it did build successfully, but when I ran it I got 0 bytes returned.

I then tested the service through SoapUI and it gave me the same code as you but still didn't work through XCode.

I then removed each line terminator one at a time until I arrived back at the code above and it worked, I've no idea why. I can only assume that Xcode was caching the previous build or something like that? but at least it's working now

THanks again for your help.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now