• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Web Service Authentication in Coldfusion

Guest
Jul 13, 2010 Jul 13, 2010

Copy link to clipboard

Copied

Hi
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

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 13, 2010 Jul 13, 2010

Copy link to clipboard

Copied

LATEST

Please try the follwoing code set

/*REMOTE METHOD

soaptest.cfc

*/

<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>

        </cfif>

        <cfreturn retunVal />

    </cffunction>

/**

/*calling remote method

index.cfm

*/
<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://localhost/testsoap/">
        <soapenv:Header>
        <setInit>1</setInit>
        </soapenv:Header>
        <soapenv:Body>
        <addNumbers soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >
        <firstNumber>1000</firstNumber>
        <secondNumber>10</secondNumber>
        </addNumbers>
        </soapenv:Body>
        </soapenv:Envelope>
</cfsavecontent>


<!--- 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)#">
</cfhttp>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation