Dart
Dart
HTTP SOAP 1.2 Request and Response using POST
See more HTTP Examples
Demonstrates a working SOAP 1.2 request and response using POST with a live server. You may try running this example with the URLs and data provided. See http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP for details.Note: This example is correct in theory, but no longer works for live testing because the SOAP service provider (cdyne.com) has made changes or discontinued the free service.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// --------------------------------------------------------------------------------
// Also see Chilkat's Online WSDL Code Generator
// to generate code and SOAP Request and Response XML for each operation in a WSDL.
// --------------------------------------------------------------------------------
final http = CkHttp();
final soapXml = CkXml();
soapXml.tag = 'soap12:Envelope';
soapXml.addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
soapXml.addAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
soapXml.addAttribute('xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope');
soapXml.newChild2('soap12:Body', '');
soapXml.getChild2(0);
soapXml.newChild2('GetCityWeatherByZIP', '');
soapXml.getChild2(0);
soapXml.addAttribute('xmlns', 'http://ws.cdyne.com/WeatherWS/');
soapXml.newChild2('ZIP', '60187');
soapXml.getRoot2();
print(soapXml.getXml());
final req = CkHttpRequest();
req.httpVerb = 'POST';
req.sendCharset = false;
req.addHeader('Content-Type', 'application/soap+xml; charset=utf-8');
req.addHeader('SOAPAction', 'http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP');
req.path = '/WeatherWS/Weather.asmx';
req.loadBodyFromString(soapXml.getXml(), 'utf-8');
http.followRedirects = true;
final resp = CkHttpResponse();
try {
http.httpSReq('wsf.cdyne.com', 80, false, req, resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final xmlResponse = CkXml();
xmlResponse.loadXml(resp.bodyStr);
print(xmlResponse.getXml());
}