I'm trying to consume a Java based SOAP web service from VBA code in an Excel 2003 workbook. There are two methods available. One retrieves data, the other uploads data. The service for retrieving data works fine. However, when we try to upload data, we're running into a strange error that I just cannot find good information about on Google. The error message is:
Run-time error '-2147221504 (800040000)';
SoapMapper: Putting data into SoapMapper element failed
If we try to consume the same web service from a .NET application, it looks like the generated classes and methods are slightly different. For example, the fetch data service call takes a DataContainer object which has some identifying properties to determine what data to get. Then it returns the same type of object with the data filled in.
In the VBA classes generated by the Web Reference Toolkit, both fetch and save take the same type of object. But in .NET, the save takes a SaveDataContainerDetails object.
So a couple questions really:
Has anyone seen the SoapMapper error before in their VBA work?
Has anyone seen .NET and VBA generate different method signatures from the same WSDL? What could cause that and how could I work around it?
Is there a better way to call SOAP services from VBA rather than using the Web Reference Toolkit and the SOAP Toolkit?
I've figured out the issue here. The VBA Soap Toolkit and Web References Toolkit just can't handle array's of complex types. The error message above was somewhat misleading because "element" was actually the name of the XML element in the Soap envelope. So it was failing to put data into an element called "element". That was masking the issue a bit.
So I've determined it all boiled down to arrays of complex types. I've also determined that it's MUCH easier to just craft the soap envelopes my self in the VBA. The XML required is generally pretty well structured and not too difficult to create and or parse. So, if you're having trouble with the Soap Toolkit or the Web References Toolkit in VBA... just don't use it! :)
The best way to consume web services from VBA, VBSCRIPT, Classic ASP, etc. is to create your client using .NET. Then turn your client into a COM object. These are easily consumed by these older technologies.
Related
I'm not sure this question is appropriate here but I hope I could get some help. What i'm looking to do is basically to make a server based iPhone application. I've got an ubuntu server ready to be used. I'm thinking of making a web service which my application then can use but I have virtually no experience in this field so i'm looking for some help to get pointed into the right direction, what language to write the web service in etc. It isn't required to be a web service but anything that make's the iPhone app depending on the server.
This little mission is simply for learning experience.
Probably PHP is what you will use to write the webservice. REST based services are the most popular, but it could be as simple as a form POST passing in parameters. The PHP script (no matter which way you write it), will then pass those parameters and any other needed info to a server method that either executes a SQL query (preferably using a stored procedure) or uses some other server resource. That data would then be output via the webservice as either XML or JSON (I personally like JSON better).
Check out Ray Wenderlich's tutorial on just this kind of thing:
When it comes time to handle the request in iOS, my personal choice is AFNetworking. It uses blocks instead of delegate methods and is blazing fast. I can hook you up with examples if needed.
Ok, First you need to learn how to write web services in PHP. Which will return you response in XML format. I personally prefer .PLIST format because it gets easier to parse on the iOS.
Once your web services are up and running. You need to use NSURLConnection and NSURLRequest to talk to your web services. Implementing the NSURLConnection Delegate methods correctly, you can download your XML response, maybe save it in a file on your Documents Directory.
Then once done downloading start parsing that response using NSXMLParser. implementing the delegates and what not, you can create your data structure the way you feel comfortable with manipulating it and store the parsed results in them and populate your View accordingly.
This is one very common question asked again and again on stack overflow and I read so many answers about this but I am still bit confused.
I need to call the webservices from iPhone sdk.
Here are my questions:
I am not clear what response SOAP or REST return.Is there anything specific that if response is XML then we should use REST and if JSON we should use SOAP?
What is the role of ASIHTTP with SOAP and REST?
If I am getting XML response as
<oproduct>
<iid>113133791</iid>
<icategoryid>270</icategoryid>
<imerchantid>1547</imerchantid>
<iadult>0</iadult>
<sname>The Ashes / 1st Test - England v Australia - Day 1</sname>
<sawdeeplink>http://www.acbcd.com/pclick.php?p=113133791&a=111402&m=1547&platform=cs</sawdeeplink>
<sawthumburl>http://images.abcdd.com/thumb/1547/113133791.jpg</sawthumburl>
<fprice>69.99</fprice>
</oproduct>
Do I need to parse it by hand? or how do I handle XML response?
I got so many articles about REST and SOAP but no proper code to understand it.
I would be grateful for any help regarding these questions.
SOAP - "Simple Object Access Protocol"
SOAP is a method of transferring messages, or small amounts of information, over the Internet. SOAP messages are formatted in XML and are typically sent using HTTP (hypertext transfer protocol).
So SOAP has a standard how a message has to be sent.
Each soap web service can be defined with a WSDL(Web Service Definition Language) which is kind of a schema for the SOAP XML transferred.
There are many tools available to convert WSDL(your webservice definition) to native code.
One of the tool available for ObjC is Sudz-C (http://sudzc.com/) which convert the WDSL of any webservice to ObjC code to access the Web service.
Rest - Representational state transfer
Rest is a simple way of sending and receiving data between client and server and it don't have any much standards defined , You can send and receive data as JSON,XML or even a Text. Its Light weighted compared to SOAP.
To handle Rest in iOS there are many tools available, I would recommend RestKit http://restkit.org/, for handling XML and JSON both.
I would suggest you to go with Rest for mobile development, since its light weight
(Simple example, People correct me If I am wrong)
Ok, so you have a few different questions here:
REST is a way of accessing the web service. SOAP is an alternative way of accessing the web service. REST uses query string or URL format whereas SOAP uses XML. JSON and XML are two different ways of sending back data. SOAP and XML are usually associated with each other. For mobile apps, REST/JSON is usually the way to go. Easier to implement and maintain, far more telegraphic, etc.
ASIHTTP, as Bill notes, is a wrapper. There are other choices that do similar things depending on what you need. If you are using REST/JSON then NSURLConnection + SBJSON might do the trick, I like it personally.
If your SOAP service has an available WSDL you can use wsdl2objc to automatically build the code for your parsing and fetching. If it is a JSON service or no WSDL is available, I would recommend using SBJSON and simply parsing in the following way:
for (id jsonElement in repsonse) {
self.propertyA = [jsonElement valueForKey:#"keyA"];
self.propertyB = [jsonElement valueForKey:#"keyB"];
}
Hope that helps!
1) SOAP responses must be XML, and to return other formats you need to either embed them in the response XML (inefficient) or use SOAP attachments (difficult). SOAP responses are contained in a soap envelope tag, and there is usually an associated wsdl. If the XML you show is all you're getting, then it may not be a SOAP service. I see links in the XML so that is a good sign that they had REST in mind.
2) I haven't heard of ASIHTTP. A quick google, and it looks like its a third party library that wraps the http interfaces in iOS. It looks like you would use that to help you make the http requests, although I would suggest that it might not be necessary; you should evaluate using the http libraries directly.
3) You need to parse it somehow. You can do it by hand, but that is generally a really bad idea. XML can come in many forms and still have the same meaning, and if you don't support all forms your application could break in the future if the web service provider began to format their XML differently, even if its semantics were the same. You would use an XML api to read the XML. The DOM api will read it into a tree form for you, and you can use XPath to extract information out of the tree.
Could anybody clarify the process of consuming aspx webservices in iOS? I have already tried JSON framework but now, need to create an app that consumes .net webservices in XML format. I need both to post some data to, and get data from the server. I already read about existing XML parsers for iOS that I found (here)
The question is do I need to do additional setup, like wrapping my query strings in SOAP or smth, in order to communicate with webserver? Would it be sufficient to use only one of mentioned libraries in the link or do I need additional stuff?
UPDATE: I found one tutorial on web (here) that demonstrates how to consume web services using Json-framework. Also, I found another one that demonstrates it using NSXMLParser (here). I'm not not very familiar with WSDL and SOAP, so any detailed explanation on how to implement would be desirable :). In both of these examples you just have to construct a request string in xml format and execute it, and that's it. Both examples actually bypasses the heavyness of SOAP and WSDL, so I was wondering do I have to know and do more that just construct a request string, execute it and get response?
While wsdl2objc is out there (as noted by #Girish Kolari), the truth is that there's no easy answer. I've never successfully gotten wsdl2objc working well for something that I couldn't have done more easily by hand. You will need to learn SOAP and WSDL. That's just a fact of life if you can't get access to a REST interface. In my experience, your best bet for simple SOAP access is to do it by hand, and your best bet for somewhat complicated SOAP access is gSOAP. Your best bet for very complicated access is to redesign something so it's not so complicated, ideally in REST. SOAP is a giant pain that some languages (C#) shield you from. ObjC does not shield you from it, so it continues to be a giant pain.
Yes, SOAP leaves a bad taste in my mouth.
I have a fair bit of experience working with the iPhone SDK. I have a couple fully developed apps including a utility application for tracking data and a board game. I would consider myself a novice on the iPhone SDK. I also have no issues with reviewing documentation and examples for hours until I understand something, as long as the documentation exists and makes sense.
I am not however an expert at XML documents and parsing attributes and creating documents. I have written in the past PHP code to access web services and complete transactions via SOAP XML messaging. I need to do a similar application using iPhone SDK. Here is what I need.
1) Create XML messages to send to a SOAP service
2) Receive XML messages from a SOAP service
3) Parse the XML response messages into a custom object
All of the URL and SOAP part is relatively straight forward. Where I start to get discouraged is the area of creating and parsing the XML messages. Using PHP these tasks are very simple as the language has built in SOAP clients and you can easily class map objects to SOAP messaging and the heavy lifting of the XML processing is just taken care of automatically. I have considered writing a proxy PHP service and simplifying what is needed on the iPhone side but this just complicates what I want and adds a dependency on another app to work in conjunction with the web service I'm accessing.
It seems that in the iPhone SDK or objective-c in general you have to be a pro at the construction and the parsing of XML messages on your own. I am really discouraged at the idea of creating tons of custom code to parse each message element by element. I've taken a small look at TouchXML / KissXML and I am not thinking they are what I need.
The real key objective here is that I want to easily receive an XML message and some how get the elements and their values copied over to an object. How can this be done without hours of writing parsing classes and understanding all of the guts of creating XML documents?
I have used Matt Gallagher's XPathQuery to great success on the iPhone. It's simple and straight-forward.
I've found, though, that the messages I have need to parse are drastically simpler than what XML (and even his simplified parser) is capable of. I've modified his source to return a data structure that's much easier to work with -- instead of having keys a bunch of keys (nodeName, nodeContent, nodeAttributeArray, attributeName, ...) for each node, I simply create nested arrays and dictionaries with the node name as the key and the content as the object directly. I completely ignore attributes, and I only use arrays if there's more than one node with the same name. Here's that code. Note that it's only been tested on the XML that I care to work with. :)
Edit: whoops, I just realized you're also looking for XML creation. This just does parsing. I'll leave it here as a partial answer.
It seems like what you really want is this:
http://code.google.com/p/wsdl2objc/
As it will create objects for you from a WSDL, and provide support code to send/receive them.
However what is mostly happening, is that people are not using SOAP for mobile web services, but instead are going to RESTFUL approaches.
That includes posting form data in HTTP POST requests or querying via GET, then getting back either JSON or plists which turn into dictionaries (JSON is more widely understood by server developers BUT you have to be more careful to correctly define the structures being passed, since you can do things like have a dictionary with the same key repeated... plists are more robust in that you can't really build anything "wrong" but is less standard on the server side).
If you have to use SOAP though, WSDL2ObjC is probably going to save you a lot of mapping.
I'm working with a third-party vendor who unfortunately requires that we set up a SOAP server to handle requests from them. I'm having some trouble finding the best way to go about this. One limitation I'm imposing is that it runs as a mod_perl2 handler. After some searching I've found that the best way may be to use XML::Compile and its SOAP classes but I'm having a tough time wrapping my head around it. Part of the problem is my limited understanding of SOAP and the documentation for most modules seems a bit cryptic to me.
So, can anyone give me some pointers, sample code, anything?
EDIT: we were also given a WSDL file to use, and this was not compatible with SOAP::WSDL ("unsupported global type found in ...
Looks like a rpc/literal WSDL, which is not supported by SOAP::WSDL)
EDIT: XML::Compile::SOAP complains "RPC encoded not supported by this version" when using the WSDL with XML::Compile::WSDL11. Can/should I not worry about the WSDL file?
If you have a limited understanding of SOAP, starting reading about SOAP before you worry about implementing it. There are lots of SOAP tutorials out there. Most of the documentation probably seems cryptic to you because you don't already know SOAP.
It's not that tricky of a process. It's not that different than any other web programming when it comes to the big steps:
You get a SOAP request, which is some XML.
You pull apart the XML to figure out what to do.
You put together some XML to send as a response.
You return the response.
XML::Compile will take care of most of the details for you.
Before you start writing your own server, you might consider writing a client for an existing SOAP server just to give yourself some practice.
I found two modules that can help you make soap server, but I never use its
https://metacpan.org/pod/XML::Compile::SOAP::Daemon
https://metacpan.org/pod/SOAP::WSDL::Server