title: ColdFusion CFHTTP connection to remote web service
body: <p>I have successfully connected to a remote webservice using SOAPUI (<a href="http://www.soapui.org" rel="nofollow noreferrer">www.soapui.org</a>). But, I am having trouble calling it successfully from CF9.2.</p>
  
  <p>Here is my entire CFC function. There are dynamic vars but I've tested the output in the soapUI interface and it works:</p>
  
  <pre><code>&lt;cffunction name="getOrganisation" access="remote" returnType="any" output="true"&gt;
  
       &lt;cfargument name="iPageNumber" type="any" required="false" default="0"&gt;
       &lt;cfargument name="iPageSize" type="any" required="false" default="0"&gt;
       &lt;cfargument name="bCurrentNamesOnly" type="boolean" required="false" default="1"&gt;
       &lt;cfargument name="bExcludeNotRtos" type="boolean" required="false" default="0"&gt;
       &lt;cfargument name="bExcludeRtoWithoutActiveRegistration" type="boolean" required="false" default="0"&gt;
       &lt;cfargument name="sFilter" type="any" required="false" default=""&gt;
       &lt;cfargument name="bIncludeCode" type="boolean" required="false" default="1"&gt;
       &lt;cfargument name="sRegistrationManagers" type="any" required="false" default=""&gt;
       &lt;cfargument name="sClassificationFilters" type="any" required="false" default=""&gt;
       &lt;cfargument name="sScheme" type="any" required="false" default=""&gt;
  
       &lt;cfset var endpoint = "https://ws.staging.training.gov.au/Deewr.Tga.WebServices/OrganisationService.svc/Organisation"&gt;
  
       &lt;cfsavecontent variable="soapBody"&gt;
            &lt;cfoutput&gt;
                 &lt;soapenv:Envelope
                      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                      xmlns:ser="http://training.gov.au/services/" 
                      xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt; 
                     &lt;soapenv:Header/&gt;               
                          &lt;soapenv:Body&gt;        
                          &lt;ser:Search&gt;
                              &lt;ser:request&gt;
                                  &lt;ser:PageNumber&gt;#arguments.iPageNumber#&lt;/ser:PageNumber&gt;
                                  &lt;ser:PageSize&gt;#arguments.iPageSize#&lt;/ser:PageSize&gt;
                                  &lt;ser:ClassificationFilters&gt;
                                     &lt;ser:ClassificationFilter&gt;
                                        &lt;ser:Scheme&gt;#arguments.sScheme#&lt;/ser:Scheme&gt;
                                        &lt;ser:Values&gt;
                                           &lt;cfif len(arguments.sClassificationFilters)&gt;
                                              &lt;cfloop list="#arguments.sClassificationFilters#" index="item"&gt;
                                                  &lt;arr:string&gt;#item#&lt;/arr:string&gt;
                                              &lt;/cfloop&gt;
                                          &lt;/cfif&gt;
                                        &lt;/ser:Values&gt;
                                     &lt;/ser:ClassificationFilter&gt;
                                  &lt;/ser:ClassificationFilters&gt;
                                  &lt;ser:CurrentNamesOnly&gt;#arguments.bCurrentNamesOnly#&lt;/ser:CurrentNamesOnly&gt;
                                  &lt;ser:ExcludeNotRtos&gt;#arguments.bExcludeNotRtos#&lt;/ser:ExcludeNotRtos&gt;
                                  &lt;ser:ExcludeRtoWithoutActiveRegistration&gt;#arguments.bExcludeRtoWithoutActiveRegistration#&lt;/ser:ExcludeRtoWithoutActiveRegistration&gt;
                                  &lt;ser:Filter&gt;#arguments.sFilter#&lt;/ser:Filter&gt;
                                  &lt;ser:IncludeCode&gt;#arguments.bIncludeCode#&lt;/ser:IncludeCode&gt;
                                  &lt;ser:RegistrationManagers&gt;
                                     &lt;cfif len(arguments.sRegistrationManagers)&gt;
                                          &lt;cfloop list="#arguments.sRegistrationManagers#" index="item"&gt;
                                              &lt;arr:string&gt;#item#&lt;/arr:string&gt;
                                          &lt;/cfloop&gt;
                                      &lt;/cfif&gt;
                                  &lt;/ser:RegistrationManagers&gt;
                               &lt;/ser:request&gt;
                          &lt;/ser:Search&gt;
                      &lt;/soapenv:Body&gt;
                  &lt;/soapenv:Envelope&gt;
              &lt;/cfoutput&gt;            
          &lt;/cfsavecontent&gt;
  
          &lt;cfhttp
                  url="#endpoint#" 
                  method="post"
                  username="#variables.username#"
                  password="#variables.password#"&gt;
  
                  &lt;cfhttpparam type="header" name="accept-encoding" value="no-compression" /&gt;
                  &lt;cfhttpparam type="xml" value="#trim(soapBody)#"/&gt;
  
          &lt;/cfhttp&gt;
  
         &lt;cfdump var="#cfhttp.FileContent#"&gt;&lt;cfabort&gt;
  
        &lt;cfreturn cfhttp.FileContent&gt;
  &lt;/cffunction&gt;
  </code></pre>
  
  <p>Running this, I get the error:</p>
  
  <pre><code>An error occurred when verifying security for the message.
  </code></pre>
  
  <p>Following is the complete return xml</p>
  
  <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;s:Body&gt;
          &lt;s:Fault&gt;
              &lt;faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;a:InvalidSecurity&lt;/faultcode&gt;
              &lt;faultstring xml:lang="en-AU"&gt;An error occurred when verifying security for the message.&lt;/faultstring&gt;
          &lt;/s:Fault&gt;
      &lt;/s:Body&gt;
  &lt;/s:Envelope&gt; 
  </code></pre>
  
  <p>So, it appears to be an authorisation issue.</p>
  
  <p>Here is the SoapUI request screen:</p>
  
  <p><img src="https://i.stack.imgur.com/meemI.gif" alt="enter image description here">  </p>
  
  <p>So, how do I construct the cfhttp, or maybe cfinvoke, to emulate the soapUI call?</p>
  
  <h2>EDIT</h2>
  
  <p>SOAP Request XML</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://training.gov.au/services/" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;ser:Search&gt;
           &lt;ser:request&gt;
              &lt;ser:PageNumber&gt;0&lt;/ser:PageNumber&gt;
              &lt;ser:PageSize&gt;0&lt;/ser:PageSize&gt;
              &lt;ser:ClassificationFilters&gt;
                 &lt;ser:ClassificationFilter&gt;
                    &lt;ser:Scheme&gt;&lt;/ser:Scheme&gt;
                    &lt;ser:Values&gt;
                       &lt;arr:string&gt;&lt;/arr:string&gt;
                    &lt;/ser:Values&gt;
                 &lt;/ser:ClassificationFilter&gt;
              &lt;/ser:ClassificationFilters&gt;
              &lt;ser:CurrentNamesOnly&gt;true&lt;/ser:CurrentNamesOnly&gt;
              &lt;ser:ExcludeNotRtos&gt;0&lt;/ser:ExcludeNotRtos&gt;
              &lt;ser:ExcludeRtoWithoutActiveRegistration&gt;0&lt;/ser:ExcludeRtoWithoutActiveRegistration&gt;
              &lt;ser:Filter&gt;&lt;/ser:Filter&gt;
              &lt;ser:IncludeCode&gt;1&lt;/ser:IncludeCode&gt;
              &lt;ser:RegistrationManagers&gt;
                 &lt;arr:string&gt;&lt;/arr:string&gt;
              &lt;/ser:RegistrationManagers&gt;
           &lt;/ser:request&gt;
        &lt;/ser:Search&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <h2>EDIT 2</h2>
  
  <p>Further information:</p>
  
  <ul>
  <li>Here is the url directly to the service: <a href="https://ws.staging.training.gov.au/Deewr.Tga.WebServices/OrganisationService.svc" rel="nofollow noreferrer">https://ws.staging.training.gov.au/Deewr.Tga.WebServices/OrganisationService.svc</a></li>
  <li>Below is a screenshot of some authentication related information from the docs
  <img src="https://i.stack.imgur.com/SFR5b.gif" alt="enter image description here"></li>
  </ul>