SOAP 1.1 Request - Content-Length Too Small

This section provides a tutorial example of SOAP 1.1 request to use the GetSpeech Web service provided at xmlme.com. A 'Bad Request' error is received, if Content-Length is not enough to cover the entire XML message in the request.

Now let's use my Perl socket test program to send a SOAP 1.1 request to a public Web service, TemperatureService, provided at my Website at: http://www.herongyang.com/Service/TemperatureService.php.

The TemperatureService Web service allows you to submit a ZIP in the request, and to receive the current temperature at that location.

Here is the request, soap_1_1_GetTemp.req:

POST /Service/TemperatureService.php HTTP/1.1
Host: www.herongyang.com
Connection: Keep-Alive
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 100

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="urn:xmethods-Temperature-Demo"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 <SOAP-ENV:Body>
  <ns1:getTemp>
   <zipcode xsi:type="xsd:string">12345</zipcode>
  </ns1:getTemp>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here is the response I got from my first test:

C:\herong>SocketRequestResponse.pl www.herongyang.com 80 
   soap_1_1_GetSpeech.req soap_1_1.res

C:\herong>more soap_1_1.res
HTTP/1.1 500 Internal Service Error
Server: Apache/2.4.12 (Win32) PHP/7.0.2
X-Powered-By: PHP/7.0.2
Content-Length: 278
Connection: close
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
 <SOAP-ENV:Body>
  <SOAP-ENV:Fault>
   <faultcode>SOAP-ENV:Client</faultcode>
   <faultstring>Bad Request</faultstring>
  </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The "Bad Request" error was expected, because I put 100 as the "Content-Length" in the request. Here is my guess on what happened to this example:

Now I learned that HTTP servers do pay attention to the "Content-Length" header line in the request. I will provide a better value for "Content-Length" and try again in the next tutorial.

Last update: 2018.

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP MEP (Message Exchange Patterns)

 SOAP HTTP Binding

 SOAP PHP Implementations

 PHP SOAP Extension Client Programs

 PHP SOAP Extension Server Programs

 PHP SOAP Web Service Example - getTemp

 SOAP Perl Implementations

 Perl SOAP::Lite - SOAP Server-Client Communication Module

Perl Socket Test Program for HTTP and SOAP

 SocketRequestResponse.pl - Socket Level Testing Program

 Examples of HTTP 1.0 Requests and Responses

 Examples of HTTP 1.1 Requests and Responses

SOAP 1.1 Request - Content-Length Too Small

 SOAP 1.1 Request - Content-Length Too Large

 SOAP 1.1 Request and Response of GetTemp

 SOAP 1.2 Request and Response of GetTemp

 Perl SOAP::Lite for NumberToWords SOAP 1.1 Web Service

 Perl SOAP::Lite for SOAP 1.2 Web Services

 Perl SOAP::Lite for WSDL

 SOAP Java Implementations

 Java Socket and HttpURLConnection for SOAP

 SAAJ - SOAP with Attachments API for Java

 SoapUI - SOAP Web Service Testing Tool

 WS-Security - SOAP Message Security Extension

 WS-Security X.509 Certificate Token

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 Web Services and SOAP Terminology

 Outdated Tutorials

 References

 Full Version in PDF/EPUB