1 Reply Latest reply on Jul 13, 2010 5:57 AM by Dileep_NR

    Web Service Authentication in Coldfusion


      I am trying to perform Web Service Authentication in Coldfusion. The webservice is written using a CFC.
      It is a normal CFC, and I am generating the Web Service URL as test.cfc?WSDL
      Is there a way that I can authenticate a web service method using SOAP headers ?


      There is a code mechanism in ASP.NET, where we can beautify the web service with codes  that will ask for a username and password for


      accessing a method of a web service.


      I am testing the web services using SOAP Sonar, it is a very good tool. When testing, if there is an authentication mechanism in a web service,


      then it will prompt you to enter the user name and password. At the moment, I have included two fields (username and password) for each


      method to do the custom authentication against a login info stored in Application.cfm.


      I found a way using WSSJ4 from Apache, but it looked too complex and not very straight forward to acheive it.


      Please if anyone have found a solution, please let me know.


      Thank you in advance..


      Josh Thomas

        • 1. Re: Web Service Authentication in Coldfusion
          Dileep_NR Level 2

          Please try the follwoing code set



          /*REMOTE METHOD




          <cffunction name="addNumbers" access="remote" returntype="test" output="false">


                  <cfargument name="firstNumber" type="string" required="true"/>


                  <cfargument name="secondNumber" type="string" required="true"/>


                  <cfset retunVal="NO">


                  <cfset username=0>


                  <cfif isSOAPRequest()>


                          <cfset retunVal="YES">


                          <cfset username = getSOAPRequestHeader("http://localhost/testsoap/", "setInit")>


                           <cfset retunVal= arguments.firstNumber + arguments.secondNumber & username>




                  <cfreturn retunVal />







          /*calling remote method


          <cfsavecontent variable="soap">
          <?xml version="1.0" encoding="UTF-8"?>
                  <addNumbers soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >


          <!--- Note that there's no ?wsdl appendage to the url --->
          <cfhttp url="http://localhost/testsoap/soaptest.cfc" method="post">
              <cfhttpparam type="header" name="content-type" value="text/xml">
              <cfhttpparam type="header" name="SOAPAction" value="">
              <cfhttpparam type="header" name="content-length" value="#len(soap)#">
              <cfhttpparam type="header" name="charset" value="utf-8">
              <cfhttpparam type="xml" name="message" value="#trim(soap)#">