title: How to form a cfhttp call to consume a custom webservice API
body: <p>I've been a cf developer for 11 years, but embarrassed to say that I've done nothing substantial with webservices.</p>
  
  <p>How to I form a cfhttp call to consume the following webservice API provided by the vendor?</p>
  
  <p><strong>Soap 1.2 Request:</strong></p>
  
  <pre><code>POST /Portal/internet.asmx HTTP/1.1
  Host: 192.168.222.240
  Content-Type: application/soap+xml; charset=utf-8
  Content-Length: length
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;soap12:Body&gt;
      &lt;Usage xmlns="http://portal/internet.asmx"&gt;
        &lt;SessionID&gt;string&lt;/SessionID&gt;
        &lt;CustomerCode&gt;int&lt;/CustomerCode&gt;
        &lt;FullUserName&gt;string&lt;/FullUserName&gt;
        &lt;StartDate&gt;dateTime&lt;/StartDate&gt;
        &lt;EndDate&gt;dateTime&lt;/EndDate&gt;
      &lt;/Usage&gt;
    &lt;/soap12:Body&gt;
  &lt;/soap12:Envelope&gt;
  HTTP/1.1 200 OK
  Content-Type: application/soap+xml; charset=utf-8
  Content-Length: length
  </code></pre>
  
  <p><strong>Soap 1.2 Response:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"&gt;
    &lt;soap12:Body&gt;
      &lt;UsageResponse xmlns="http://portal/internet.asmx"&gt;
        &lt;UsageResult&gt;
          &lt;xsd:schema&gt;schema&lt;/xsd:schema&gt;xml&lt;/UsageResult&gt;
      &lt;/UsageResponse&gt;
    &lt;/soap12:Body&gt;
  &lt;/soap12:Envelope&gt;
  </code></pre>
  
  <p>I want to do it manually at the moment (I know about cfinvoke and createobject). I came up with the following from a Ben Nadel blog, but I get a "connection failure" error. I guess I just need someone to check for obvious flaws in the code before I look at whether it is genuinely connection/authorisation related.</p>
  
  <pre><code>&lt;cfsavecontent variable="soapBody"&gt;
   &lt;cfoutput&gt;
    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;soap:Envelope 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
              xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
            &lt;soap:Body&gt;
              &lt;Usage xmlns="http://portal/internet.asmx"&gt;
                &lt;SessionID&gt;F7B3B3FB-DE35-45CB-A785-8229E91FAEC9&lt;/SessionID&gt;
                &lt;CustomerCode&gt;1112221&lt;/CustomerCode&gt;
                &lt;FullUserName&gt;MR DAVE GEORGE&lt;/FullUserName&gt;
                &lt;StartDate&gt;2010-01-01&lt;/StartDate&gt;
                &lt;EndDate&gt;2009-01-01&lt;/EndDate&gt;
              &lt;/Usage&gt;
            &lt;/soap:Body&gt;
          &lt;/soap:Envelope&gt;
  
   &lt;/cfoutput&gt;
  &lt;/cfsavecontent&gt;
  
  
  &lt;cfhttp
   url="http://portal/internet.asmx"
   method="post"
   result="httpResponse"&gt;
  
   &lt;cfhttpparam
    type="header"
    name="SOAPAction"
    value="http://portal/internet.asmx/Usage"
    /&gt;
  
   &lt;cfhttpparam
    type="header"
    name="accept-encoding"
    value="no-compression"
    /&gt;
  
   &lt;cfhttpparam
    type="xml"
    value="#trim( soapBody )#"
    /&gt;
  
  &lt;/cfhttp&gt;
  
  
  
   &lt;cfoutput&gt;
   #httpResponse.fileContent# &lt;!--- ouputs "connection failure" ---&gt;
      &lt;/cfoutput&gt; 
  </code></pre>
  
  <p>Many thanks,
  Paul</p>