Fallenreaper Fallenreaper - 3 years ago 280
Dart Question

How does Dart leverage SOAP requests?

I was looking up how to do SOAP requests within Dart. When looking at HTTPRequest it really only mentions RESTful services and wanted to make sure that this can be done.

Right now, I have my server, username, and password. Trying to get a successful authentication via the service, so that way I have an auth token i can pass when doing subsequent calls.

It seems for example in .NET, it does the following and then stores the credential in a server side session variable which I was using as a starting point to make this in Dart.

// create web service api object
WebServiceAPI api = new WebServiceAPI();

if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["ProxyUserName"]))
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["ProxyUserName"], ConfigurationManager.AppSettings["ProxyPassword"], ConfigurationManager.AppSettings["ProxyDomain"]);
System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(api.Url), "NTLM", nc);
api.Credentials = cc;

api.AuthenticateCredential("api@admin", "admin", 0, 0);
HttpContext.Current.Session["api"] = api;

Edit: I am adding some sample data such that if there is a hack we can leverage to get something working, we might be able to abstract it and genericize.

service asmx file:

Method we will be calling: (AuthenticateCredential)

The sample SOAP request:
POST /service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://foo.com/bar/320/Default/AuthenticateCredential"

<?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/">
<AuthenticateCredential xmlns="http://foo.com/barr/320/Default">

then naturally, I will have to write up and mod the
out of the envelope. such that the credentials are correct.

Answer Source

I've performed SOAP actions for Blackboard's web services using Dart, so it's possible. To do so, I had to build the SOAP envelope programmatically for each request. The requests themselves were sent using the http package's 'post' method.

Can't say how your requests should be set up, that would depend on the web service you're attempting to access. For the HTTP headers, I sent a 'Content-Type' of 'text/xml; charset=utf-8' and a 'SOAPAction' header specifying the SOAP method. The body was the full SOAP envelope.

You may need to play around a bit to build the envelope with the correct format/info your service expects. I used the xml package to parse/interpret the responses.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download