Uderc programming article aggregator sites

Webservice API call

Tags:
Answers: Have 21 answers
Advertisement
I have been trying to make Webservice call to "https://webservice.exacttarget.com/etframework.wsdl" using coldfusion server 9.0 without much success. My code recognizes WSDL and it methods but When I call method it throws following error:
Web service operation Describe with parameters {{DESCRIBEREQUESTS={[Lcom.et.client.ObjectDefinitionRequest;@78b0e1}}} cannot be found.
Please suggest.....
MyCode CFM file code:
Package Class: "com.et.client"
<cfsilent>
    <cffunction name="head1" access="private" returntype="Any" output="false"
                hint="Return the header needed to make an Omniture web service request as a SOAPHeaderElement object">
        <cfargument name="strUsername" type="String" required="true" />
        <cfargument name="strSecret" type="String" required="true" />
        <cfscript>
            // Unique random number
            var strNonce = createUUID();
            var strCreated  = DateFormat(Now(),'YYYY-mm-dd H:mm:ss');
            var strPassword = arguments.strSecret;
            // Start to build header
            var objHeader = CreateObject("java", "org.apache.axis.message.SOAPHeaderElement");
            var nodeUserToken = "";
            var nodePassword = "";
            // Construct XML structure with code
            objHeader.init("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse:Security");
            objHeader.setMustUnderstand(1);
            objHeader.setActor("");
            nodeUserToken = objHeader.addChildElement("wsse:UsernameToken");
            nodeUserToken.setAttribute("wsu:Id", "User");
            nodeUserToken.addChildElement("wsse:Username").setValue(arguments.strUsername);
            nodePassword = nodeUserToken.addChildElement("wsse:Password");
            nodePassword.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0##Passwo rdText");
            nodePassword.setValue(strPassword);
            nodeUserToken.addChildElement("wsse:Nonce").setValue(strNonce);
            nodeUserToken.addChildElement("wsu:Created").setValue(strCreated);
        </cfscript>
        <cfreturn objHeader />
    </cffunction>
    <cfscript>
        objHeader = head1("test", "[email protected]");
        objService = CreateObject("webservice", "https://webservice.exacttarget.com/etframework.wsdl");
        objService.setHeader(objHeader);
                                definitionRequest =  createObject("java", "com.et.client.ObjectDefinitionRequest").init();
                                definitionRequest.setObjectType("Account");
                                DefinitionRequestMsg  = StructNew();                               
                                defre = arraynew(1);
                                defre[1] =definitionRequest;
                                DefinitionRequestMsg.DescribeRequests = JavaCast("com.et.client.ObjectDefinitionRequest[]",defre);
   </cfscript>
</cfsilent>
</br>
SubKey ::: <cfdump var="#sub.SubscriberKey#">
<br/>
<p>
Type ::: <cfdump var="#definitionRequest.getObjectType()#">
<br/>
<p>
DefinitionRequestMsg ::: <cfdump var="#DefinitionRequestMsg.DescribeRequests[1].ObjectType#">
<br/>
<p>
Methods ::: <cfdump var="#objService#">
<br/>
<cfscript>
objService.Describe(DefinitionRequestMsg);
resp = getSOAPResponse(objService);
OutPut:
SubKey :::   Jon_Doe 
Type :::   Account
DefinitionRequestMsg :::   Account
Methods ::: 
object of com.exacttarget.wsdl.partnerAPI.SoapBindingStub
Class Name
com.exacttarget.wsdl.partnerAPI.SoapBindingStub
Methods
Method
Return Type
configure(com.exacttarget.wsdl.partnerAPI.ConfigureRequestMsg)
com.exacttarget.wsdl.partnerAPI.ConfigureResponseMsg
create(com.exacttarget.wsdl.partnerAPI.CreateRequest)
com.exacttarget.wsdl.partnerAPI.CreateResponse
delete(com.exacttarget.wsdl.partnerAPI.DeleteRequest)
com.exacttarget.wsdl.partnerAPI.DeleteResponse
describe(com.exacttarget.wsdl.partnerAPI.DefinitionRequestMsg)
com.exacttarget.wsdl.partnerAPI.DefinitionResponseMsg
execute(com.exacttarget.wsdl.partnerAPI.ExecuteRequest[])
com.exacttarget.wsdl.partnerAPI.ExecuteResponseMsg
extract(com.exacttarget.wsdl.partnerAPI.ExtractRequest[])
com.exacttarget.wsdl.partnerAPI.ExtractResponseMsg
getSystemStatus(com.exacttarget.wsdl.partnerAPI.SystemStatusRequestMsg)
com.exacttarget.wsdl.partnerAPI.SystemStatusResponseMsg
perform(com.exacttarget.wsdl.partnerAPI.PerformRequestMsg)
com.exacttarget.wsdl.partnerAPI.PerformResponseMsg
query(com.exacttarget.wsdl.partnerAPI.QueryRequestMsg)
com.exacttarget.wsdl.partnerAPI.QueryResponseMsg
retrieve(com.exacttarget.wsdl.partnerAPI.RetrieveRequestMsg)
com.exacttarget.wsdl.partnerAPI.RetrieveResponseMsg
schedule(com.exacttarget.wsdl.partnerAPI.ScheduleRequestMsg)
com.exacttarget.wsdl.partnerAPI.ScheduleResponseMsg
update(com.exacttarget.wsdl.partnerAPI.UpdateRequest)
com.exacttarget.wsdl.partnerAPI.UpdateResponse
versionInfo(com.exacttarget.wsdl.partnerAPI.VersionInfoRequestMsg)
com.exacttarget.wsdl.partnerAPI.VersionInfoResponseMsg
Fields
Field
Value
java.lang.String ENDPOINT_ADDRESS_PROPERTY
javax.xml.rpc.service.endpoint.address
java.lang.String PASSWORD_PROPERTY
javax.xml.rpc.security.auth.password
java.lang.String SESSION_MAINTAIN_PROPERTY
javax.xml.rpc.session.maintain
java.lang.String USERNAME_PROPERTY
javax.xml.rpc.security.auth.username
Parent Class
The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Web service operation Describe with parameters {{DESCRIBEREQUESTS={[Lcom.et.client.ObjectDefinitionRequest;@78b0e1}}} cannot be found.
The error occurred in /Users/bgogineni/ColdFusion/wwwroot/ET/index2.cfm: line 84
82 : <br/> 83 : <cfscript>
84 :  objService.Describe(DefinitionRequestMsg); 85 :  resp = getSOAPResponse(objService); 86 :
Resources:
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser 
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9
Remote Address 
127.0.0.1
Referrer 
Date/Time 
13-May-10 10:27 PM
Stack Trace
at cfindex22ecfm949006999.runPage(/Users/bgogineni/ColdFusion/wwwroot/ET/index2.cfm:84)                  
coldfusion.xml.rpc.ServiceProxy$ServiceMethodNotFoundException: Web service operation Describe with parameters {{DESCRIBEREQUESTS={[Lcom.et.client.ObjectDefinitionRequest;@78b0e1}}} cannot be found. at coldfusion.xml.rpc.ServiceProxy.invokeImpl(ServiceProxy.java:256) at coldfusion.xml.rpc.ServiceProxy.invoke(ServiceProxy.java:154) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360) at cfindex22ecfm949006999.runPage(/Users/bgogineni/ColdFusion/wwwroot/ET/index2.cfm:84) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:363) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:87) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:53) at coldfusion.CfmServlet.service(CfmServlet.java:200) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Debugging Information
ColdFusion Server Enterprise
9,0,0,251028
Template
/ET/index2.cfm
Time Stamp
13-May-10 10:27 PM
Locale
English (US)
User Agent
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9
Remote IP
127.0.0.1
Host Name
localhost
Execution Time  
Total Time
Avg Time
Count
Template
15 ms
15 ms
1
/Users/bgogineni/ColdFusion/wwwroot/ET/index2.cfm
14 ms
STARTUP, PARSING, COMPILING, LOADING, & SHUTDOWN
29 ms
TOTAL EXECUTION TIME
red = over 250 ms average execution time   
Exceptions  
22:27:34.034 - Application Exception - in /Users/bgogineni/ColdFusion/wwwroot/ET/index2.cfm : line 84
    Web service operation Describe with parameters {{DESCRIBEREQUESTS={[Lcom.et.client.ObjectDefinitionRequest;@78b0e1}}} cannot be found.    
Thanks
-GBK
Advertisement
The best answer: We do a lot of work with web service APIs using coldfusion.  A while ago, we decided it was much easier (especially when dealing with complex web service invocations) to switch to posting/receiving the raw XML SOAP messages in order to exchange data with the remote web service.  Ben Nadel has a great article that outlines what is involved:
http://www.bennadel.com/blog/1809-Making-SOAP-Web-Service-Requests-With-ColdFusion-And-CFH TTP.htm
What's more, you can use a lot of free/OSS tools to generate a template for the Request/Response SOAP messages, so it really just winds up being a matter of creating your XML in a cfsavecontent block and adding your variables in place of the sample text.  We use SOAPSonar from Crosscheck networks (http://www.crosschecknet.com/products/soapsonar.php) - they have a free "personal" edition that will parse a WSDL and generate the resulting XML SOAP messages that you can use as a template.
The only major issue is you have to watch out for the XML namespaces in the response that comes back from the web service.  ColdFusion (not surprisingly) has a major issue with extracting data using XMLSearch() from an XML node that includes a name space.  There are a couple of work-arounds - you could use a local-name() xpath method to perform a namespace-agnostic search, or you could use regular expressions to just strip all the namespace data out of the XML and parse using ColdFusion.
Anyway, the implementation winds up looking something like this:
<!--- build Soap XML --->
<cfsavecontent variable="sSOAPBody">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
     <myMethod>
          <firstArgument>#MyValue#</firstArgument>
     </myMethod>
</soap:Body>
</soap:Envelope>
</cfoutput>
</cfsavecontent>
<!--- Send SOAP data using CFHTTP --->
<cfhttp url="URL of Web service (e.g. .asmx, .cfc - no WSDL)" method="post">
<cfhttpparam type="header" name="SOAPAction" value="http://target_namespace_goes_here/method">
<cfhttpparam type="header" name="accept-encoding" value="no-compression">
<cfhttpparam type="xml" value="#trim(sSOAPBody)#">
</cfhttp>
<!--- Parse XML Response in CFHTTP.FileContent --->