title: How to get value from Flutter/Dart Soap web services asmx call?
body: <p>I am trying to understand how Flutter and Dart uses soap web services asmx. For this I created very basic project and used online soap WebService asmx for test. </p>
  
  <p>Using <a href="http://www.dneonline.com/calculator.asmx?op=Add" rel="nofollow noreferrer">http://www.dneonline.com/calculator.asmx?op=Add</a> I successfully build my envelope in Flutter. </p>
  
  <p>In test I use the <strong>SOAP 1.1</strong> part.</p>
  
  <p>First I failed to run the app but luckily I found the error on "<strong>Content-Length: length</strong>". So I remove it and all worked very well. </p>
  
  <p>Its a basic calculator (add) functionality. First I don't know how to add integer inside the envelope, so I use static hard coded values.</p>
  
  <p>In response body I found the <strong>&lt; AddResult > 9 &lt; / AddResult ></strong> line that has the my answer from soap call.</p>
  
  <p>Second thing is (this is my question) I get response body, but I don't know how to get the value from the body.</p>
  
  <p>How to get value from Flutter/Dart Soap web services asmx call?</p>
  
  <p><strong>This is my full Flutter code.</strong></p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Flutter Demo Home Page'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    int _firstInteger = 5;
    int _secondInteger = 4;
  
    var envelope =
        "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;&lt;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/\"&gt; &lt;soap:Body&gt; &lt;Add xmlns=\"http://tempuri.org/\"&gt; &lt;intA&gt;5&lt;/intA&gt; &lt;intB&gt;4&lt;/intB&gt;&lt;/Add&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;";
    var _testValue = "";
    bool _add = true;
  
    @override
    void initState() {
      // TODO: implement initState
      super.initState();
      _add = true;
    }
  
    Future _getCalculator() async {
      http.Response response =
          await http.post('http://www.dneonline.com/calculator.asmx',
              headers: {
                "Content-Type": "text/xml; charset=utf-8",
                "SOAPAction": "http://tempuri.org/Add",
                "Host": "www.dneonline.com"
              },
              body: envelope);
  
      setState(() {
        _testValue = response.body;
        _add = true;
      });
      print(response.body);
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Center(
            child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            _add == true
                ? new Text(
                    "Answer: $_testValue",
                    style: new TextStyle(
                        fontSize: 18.0,
                        fontWeight: FontWeight.bold,
                        color: Colors.red[800]),
                  )
                : new CircularProgressIndicator(),
            new RaisedButton(
              onPressed: () {
                setState(() {
                  _add = false;
                });
                _getCalculator();
              },
              child: new Text("Calculate"),
            )
          ],
        )),
      );
    }
  }
  </code></pre>
  
  <p><strong>And this is the response.body output:</strong></p>
  
  <pre><code>I/flutter ( 6414): &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Body&gt;&lt;AddResponse xmlns="http://tempuri.org/"&gt;&lt;AddResult&gt;9&lt;/AddResult&gt;&lt;/AddResponse&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt;
  </code></pre>