DEFAULT_HTTP_CONTENT_TYPE='application/soap+xml'

This section provides a tutorial example on how to override the constant DEFAULT_HTTP_CONTENT_TYPE in the SOAP::Lite module to use 'application/soap+xml' for SOAP 1.2.

At this point, the last issue of using SOAP::Lite to call the SOAP 1.2 GetSpeech Web service is to set the "application/soap+xml" as the media type in the Content-Type header line.

How should I do this? The SOAP::Lite manual does not offer any explicit method for me to reset Content-Type header line.

I did some research on the Internet, and found no suggestions on how to control Content-Type with SOAP::Lite.

So I had to read the source code of SOAP::Lite and related modules. If you open \local\Perl\site\lib\SOAP\Transport\HTTP.pm, you will see this code segment:

sub send_receive {
...
      if(!$http_request->content_type) {
          $http_request->content_type(join '; ',
               $SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE,
               !$SOAP::Constants::DO_NOT_USE_CHARSET && $encoding
                   ? 'charset=' . lc($encoding)
                   : ()
          );
      }
...
}

This logic says, if $http_request->content_type is defined explicitly, use it as is. Otherwise, built it based on the constant, $SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE.

If my understanding is correct, my first option is to fix the constant DEFAULT_HTTP_CONTENT_TYPE. If you open \local\Perl\site\lib\SOAP\Constants.pm, you will see this section:

    1.2 => {
        NEXT_ACTOR                => URI_SOAP12_NEXT_ACTOR,
        NS_ENV                    => URI_SOAP12_ENV,
        NS_ENC                    => URI_SOAP12_ENC,
        DEFAULT_XML_SCHEMA        => URI_2001_SCHEMA_XSD,
        DEFAULT_HTTP_CONTENT_TYPE => 'application/soap',
    },

Obviously, I can reset this constant after I run $client->soapversion('1.2') like this:

#- GetSpeech_Default_HTTP_Content_Type.pl
#- Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
#- All rights reserved
#
   use SOAP::Lite +trace;
   my $client = SOAP::Lite->new()
      ->soapversion('1.2')
      ->envprefix('soap12')
      ->default_ns('http://xmlme.com/WebServices')
      ->on_action( sub {join '/', @_} )
      ->readable(true)
      ->proxy('http://localhost/WSShakespeare.asmx');

#- Overriding the constant
   $SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE 
      = 'application/soap+xml';

   my $som = $client->call('GetSpeech', 
      SOAP::Data->name("Request")
      ->value("To be, or not to be")
   );

Result of GetSpeech_Default_HTTP_Content_Type.pl:

POST http://localhost/WSShakespeare.asmx HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 606
Content-Type: application/soap+xml; charset=utf-8
SOAPAction: http://xmlme.com/WebServices/GetSpeech
...

It worked! Remember you must override DEFAULT_HTTP_CONTENT_TYPE after calling soapversion('1.2'), not before. soapversion('1.2') triggers the 1.2 version of constants to be used.

Last update: 2009.

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 Message Exchange Patterns

 SOAP HTTP Binding

 SOAP Perl Implementations

 SOAP PHP Implementations

 SOAP Java Implementations

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

 Perl Socket Test Program for HTTP and SOAP

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Installing SOAP::Lite 0.710 to Support SOAP 1.2

 Features in SOAP::Lite 0.710

 Methods on SOAP::Lite 0.710 Client Object

 Testing SOAP::Lite Client Objects

 Request Differences between SOAP 1.1 and SOAP 1.2

 GetSpeech_localhost.pl - Testing GetSpeech on Local Host

 soapversion('1.2') and envprefix('soap12') Must Used Together

 default_ns() - Setting Default namespace for Body Elements

 SOAP::Data - Utility Class to Generate XML Elements

 SOAPAction - Not Needed, But No Way to Remove It

 Unsupported Media Type: "application/soap"

DEFAULT_HTTP_CONTENT_TYPE='application/soap+xml'

 content_type() method in the HTTP::Headers Class

 GetSpeech_SOAP_1_2.pl - SOAP::Lite for SOAP 1.2 Web Service

 Perl SOAP::Lite 0.710 for WSDL

 PHP SOAP Extension Client Programs

 PHP SOAP Extension Server Programs

 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

 Web Services and SOAP Terminology

 References

 PDF Printing Version