title: SOAP client using perl - WSDL URL is available
body: <p>I have a powershell script which will make a soap call, and perform the following operations:
  1.Connects to the server hosting the WSDL (called cell in application terminology)
  2.Creates an event(alert) in it.
  3.Disconnects from the server hosting the WSDL(called cell in application terminology)
  I want to create perl version of this script.. which does the same exact operations,Please help me with functions and examples. or if possible by rewriting the below script in perl.
  Thank you so much in advance:</p>
  
  <p>the PS script is as below:</p>
  
  <p>===============================================================================</p>
  
  <pre><code>$severity = "MAJOR"
  
  $msg = "Test event from Powershell"
  $cellname = "mycell"
  
  $url = "http://iiwshostname:9080/imws/services/ImpactManager/"
  $headers = @{ "SOAPAction" = "Connect"}
  $soap = [xml]@"
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:imap="http://blueprint.bmc.com/ImapiElems"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;imap:Connect&gt;
           &lt;imap:userName&gt;admin&lt;/imap:userName&gt;
           &lt;imap:password&gt;admin&lt;/imap:password&gt;
           &lt;imap:imname&gt;$cellname&lt;/imap:imname&gt;
           &lt;imap:bufferType&gt;BMCII_BUFFER_MODE_DEFAULT&lt;/imap:bufferType&gt;
        &lt;/imap:Connect&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  "@
  [xml]$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers
  $connectionId = $ret.GetElementsByTagName("imap:connectionId").'#text'
  
  $headers = @{ "SOAPAction" = "SendEvent"}
  $soap = [xml]@"
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:imap="http://blueprint.bmc.com/ImapiElems" xmlns:bas="http://blueprint.bmc.com/BasicTypes" xmlns:even="http://blueprint.bmc.com/Event"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;imap:SendEvent&gt;
           &lt;imap:connection&gt;$connectionId&lt;/imap:connection&gt;
           &lt;imap:message&gt;    
              &lt;bas:NameValue_element&gt;    
                 &lt;bas:name&gt;msg&lt;/bas:name&gt;    
                 &lt;bas:value&gt;    
                    &lt;bas:string_value&gt;$msg&lt;/bas:string_value&gt;    
                 &lt;/bas:value&gt;    
                 &lt;bas:value_type&gt;STRING&lt;/bas:value_type&gt;    
              &lt;/bas:NameValue_element&gt;    
              &lt;bas:NameValue_element&gt;    
                 &lt;bas:name&gt;severity&lt;/bas:name&gt;    
                 &lt;bas:value&gt;    
                    &lt;bas:string_alue&gt;$severity&lt;/bas:string_value&gt;    
                 &lt;/bas:value&gt;   
                 &lt;bas:value_type&gt;STRING&lt;/bas:value_type&gt;    
              &lt;/bas:NameValue_element&gt;              
              &lt;even:subject&gt;&lt;/even:subject&gt;    
           &lt;/imap:message&gt;    
           &lt;imap:timeout&gt;60&lt;/imap:timeout&gt;    
           &lt;imap:messageClass&gt;EVENT&lt;/imap:messageClass&gt;    
           &lt;imap:messageType&gt;MSG_TYPE_NEW_EVENT&lt;/imap:messageType&gt;    
        &lt;/imap:SendEvent&gt;    
     &lt;/soapenv:Body&gt;    
  &lt;/soapenv:Envelope&gt;    
  "@    
  [xml]$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers    
  
  $mc_ueid = $ret.GetElementsByTagName("imap:response").'#text'    
  
  $headers = @{ "SOAPAction" = "Disconnect"}    
  $soap = [xml]@"    
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soapenvelope/" xmlns:imap="http://blueprint.bmc.com/ImapiElems"&gt;
         &lt;soapenv:Header/&gt;
         &lt;soapenv:Body&gt;
            &lt;imap:Disconnect&gt;
               &lt;imap:connection&gt;$connectionId&lt;/imap:connection&gt;
               &lt;imap:deleteBuffer&gt;No&lt;/imap:deleteBuffer&gt;    
        &lt;/imap:Disconnect&gt;    
     &lt;/soapenv:Body&gt;    
  &lt;/soapenv:Envelope&gt;    
  "@    
  $ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers    
  
  write-host $mc_ueid
  </code></pre>
  
  <p>===============================================================================</p>