SOAP Request doesn't work.

Hey together,

i created a webservice on SOAP/WSDL the webservice works fine (tested with http://www.soapclient.com/soaptest.html.) The Wifi Client (ESP8266) works fine as well.

Now i tried to call the webservice from the arduino, i cant get it to work, do you have some ideas?


if (client.connect("isnotpublic.de", 80)) {
    client.println("POST /m/w/messstation.wsdl HTTP/1.1");
    client.println("Host: isnotpublic.de");
    client.println("Content-Type: text/xml; charset=utf-8");
    client.println("Content-Length:934");
    client.println("SOAPAction: \"http://example.com/getData\">");
    client.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    client.println("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"https://isnotpublic/messstation\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >");
    client.println("<SOAP-ENV:Body>");
    client.println("<mns:setData xmlns:mns=\"urn:xmethods-delayed-quotes\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
    client.println("<mac xsi:type=\"xsd:string\"></mac>");
    client.println("<temp xsi:type=\"xsd:string\">100</temp>");
    client.println("<co xsi:type=\"xsd:string\"></co>");
    client.println("<humid xsi:type=\"xsd:string\"></humid>");
    client.println("<uv xsi:type=\"xsd:string\"></uv>");
    client.println("<druck xsi:type=\"xsd:string\"></druck>");
    client.println("<pm25 xsi:type=\"xsd:string\"></pm25>");
    client.println("<pm10 xsi:type=\"xsd:string\"></pm10>");
    client.println("</mns:setData>");
    client.println("</SOAP-ENV:Body>");
    client.println("</SOAP-ENV:Envelope>");
    client.println();
    client.stop();
    Serial.println("MAKE REQUEST DONE");
  }

Thank you for your time!

Flo

This is just an excerpt, post the complete code if you want to get all problems.

First there’s no empty line to signal the end of the HTTP header.
Then there’s a SOAP action header line that’s probably just copy/paste from an example but doesn’t match the intention. If your server implementation is conforming to the standard it should not ignore it.

Don’t use HTTP/1.1 if you don’t know what the difference to version 1.0 is! As you don’t handle persistent connections you must include a header line “Connection: close”.

There may be other problems but I stopped because of the missing rest of the code.

What Arduino are you using that on?

Hey pylon,

i use an Arduino Mega 2560 - i added the full code.
I checked out the defference between HTTP 1.1 and HTTP 1.0 and updated the code do 1.0.

#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <Wire.h>
#include <avr/sleep.h>

char ssid[] = "xxxxxxxxxxxxxx";            // your network SSID (name)
char pass[] = "xxxxxxxxxxxxxxxxxx";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

WiFiEspClient client;

void setup() {
  
  Serial.begin(19200);
  Serial2.begin(115200);
  Serial1.begin(9600);
  
  WiFi.init(&Serial2);

  if (WiFi.status() == WL_NO_SHIELD) {
    while (true);
  }

  while ( status != WL_CONNECTED) {
    status = WiFi.begin(ssid, pass);
  }
}

void loop() {
  
  soapEnvelope();
  delay(10000);
  
}

String soapEnvelope()
{
  Serial.println("In SOPA");
   if (client.connect("isnotpublic.de", 80)) {
    Serial.println("Connected to Servert");
    client.println("POST /ws/webservice/ws.php HTTP/1.0");
    client.println("Host: isnotpublic.de");
    client.println("Content-Type: text/xml; charset=utf-8");
    client.println("Content-Length:1262");
    client.println("SOAPAction: \"setData\">");
    client.println();
    client.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    client.println("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"https://isnotpublic.de/ws\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >");
    client.println("<SOAP-ENV:Body>");
    client.println("<mns:setData xmlns:mns=\"urn:xmethods-delayed-quotes\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
    client.println("<mac xsi:type=\"xsd:string\"></mac>");
    client.println("<temp xsi:type=\"xsd:string\">100</temp>");
    client.println("<co xsi:type=\"xsd:string\">12</co>");
    client.println("<humid xsi:type=\"xsd:string\"></humid>");
    client.println("<uv xsi:type=\"xsd:string\"></uv>");
    client.println("<druck xsi:type=\"xsd:string\"></druck>");
    client.println("<pm25 xsi:type=\"xsd:string\"></pm25>");
    client.println("<pm10 xsi:type=\"xsd:string\"></pm10>");
    client.println("</mns:setData>");
    client.println("</SOAP-ENV:Body>");
    client.println("</SOAP-ENV:Envelope>");
 client.println("Connection: close");
    client.println();
    client.stop();
    Serial.println("MAKE REQUEST DONE");
  }
}

"Connection: close" is a header line and must not be part of the body!

How do you get to a content length of 1262? My calculation results in slighly more than 900 bytes.

Use the F() for these strings. Although the Mega2560 has 8kB of RAM you should not waste it for unnecessary things.