1

I need to consume a asp.net web service using ColdFusion 8 and return an XML file.

I am able to communicate with asp.net service but am returned an error from the service that basically says the information I passed was not valid.

Here is a run down of my code :

<cfxml variable="soap">
<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"   
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
<cfoutput> <GetSession xmlns="#stagingurl#"></cfoutput>  
  <strApplicationKey>myappkey</strApplicationKey>
  <UID>myuserid</UID>
  <arrProperties>
    <Property>
      <Name>IP</Name>
      <Value>127.0.0.1</Value>
    </Property>
  </arrProperties>
  <arrRoles />
</GetSession>
</soap:Body>
</soap:Envelope>         
</cfxml>

<cfhttp url="#apiurl#" method="post" result="httpresponse" port="443">

  <cfhttpparam type="header" name="content-type" value="text/xml"> 
  <cfhttpparam type="header" name="SOAPAction" value="#mysoapaction#"> 
  <cfhttpparam type="header" name="content-length" value="#len(trim(soap))#"> 
  <cfhttpparam type="header" name="charset" value="utf-8">
  <cfhttpparam type="Body" value="#trim(soap)#" name="FileContent"/>  

</cfhttp>

<cfdump var="#GetHttpRequestData()#" label="Get Http Request Data" />

Is there a way to preview the information being sent to make sure that ColdFusion is actually sending my XML/SOAP request?

I did use #GetHttpRequestData()# to return some data and within the structure, content is "empty string" and this is where I need help. Should this be empty? This is new for me, but, I guess I expected that my information being passed to the asp.net service would be in there.

FYI - I can see the HTTP and SOAP response fine, I just can not see the request information. How do I view the Request information?

Still trying to determine if the issue is on my end, or theirs and need to gather facts at this point.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
Green067
  • 13
  • 2

3 Answers3

2

Another invaluable tool when working with web services is soapUI. That should definitely be a part of your toolkit as well. You can build your request using soapUI and check the responses. Once you have it working with soapUI you can copy your request into your ColdFusion code.

One thing that I noticed is that your are wrapping your XML in a cfxml tag. I'm not sure if that is messing with your request or not. I typically wrap my XML request in cfsavecontent tags. So you could try changing your code like this:

<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
   <cfoutput> <GetSession xmlns="#stagingurl#"></cfoutput>  
   <strApplicationKey>myappkey</strApplicationKey>
   <UID>myuserid</UID>
   <arrProperties>
     <Property>
       <Name>IP</Name>
       <Value>127.0.0.1</Value>
     </Property>
   </arrProperties>
   <arrRoles />
   </GetSession>
   </soap:Body>
</soap:Envelope>         
</cfsavecontent>

The rest of your code can remain the same.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • @ Miguel-F -- I used this route too and although there are no syntax errors, the ASP.Net service returns that I did not send the correct information. (Invalid UID) Even though when I output the format of the XML being sent, it is properly formatted. Which is why I am trying to see the information actually being sent off the CF Server BEFORE it hits the ASP.Net server. I am working with my IT guys to get Fiddler or SOAPUI installed right now. – Green067 Sep 18 '12 at 18:52
  • @Green067 - I would say that you are on the right track getting soapUI installed. It is invaluable for testing webservices. From your comment it sounds like the call is working but the service is simply complaining about the UID that was passed. To me that sounds like it received the request, parsed the XML but does not recognize the passed UID. Silly question - do you have your ColdFusion variable enclosed with `#` in your code? Like this `#myuserid#`? – Miguel-F Sep 18 '12 at 19:10
  • I installed SOAPUI and realized that the documentation the client provided had the wrong XML. I used the XML provided in SOAPUI and it immediately worked. Thanks! – Green067 Oct 13 '12 at 22:15
1

If you're on Windows (or have a windows machine to hand) install Fiddler and start it. It's a proxy that listens on port 8888 by default so in your cfhttp call, add proxyServer="127.0.0.1" and proxyPort="8888" and run your request again.

Just noticed that you're using port 443, so probably SSL. You can enable HTTPS decrypt Tools->Fiddler Options->HTTPS Tab->Decrypt HTTPS traffic. You may then also need to import the Certificate that Fiddler uses into your keystore.

Each request will now show up in Fiddler and you can use the request and response inspectors on the right to look at the exact data going between the servers (the Raw tab shows the data unchanged). This has saved me so many times and is now part of my standard toolkit.

In your particular case, is there a reason you're not using CreateObject("webservice","http://....") . I'm assuming that it's not playing well with a .Net-based webservice?

Also, the call to GetHttpRequestData() shows the request you made to your test page, not the HTTP call you made to the test webservice. Unfortunately, CFHTTP doesn't return any structure showing the full HTTP request details it used. I think that would be a pretty sound feature request, as at the moment, you'll have to use a tool like fiddler or wireshark to see what was sent.

Community
  • 1
  • 1
barnyr
  • 5,678
  • 21
  • 28
  • Thanks for your help so far. Still scratching my head at how to do this. As I said, I am new to webservices. Question on the CreateObject method... will this allow me to send and receive XML data? On my first attempt, the call returns an error. Web service cannot be found. I used the same .asmx file path from before, so, I am not sure where I am going wrong. – Green067 Sep 18 '12 at 18:46
  • The CreateObject method creates stubs for the XML types that you need to send to a webservice and it takes care of converting your data structures to XML. You need to provide the URL of the WSDL for your webservice for CreateObject to work. Also, can you get the WSDL in your browser without and password/SSL warning? If you need to do anything like that then CF will have similar troubles. If you can get CreateObject to work, then CFDump the newly created object and look at the methods on it, they should correspond to the methods on the Web Service – barnyr Sep 21 '12 at 11:39
0

Simple issue with dot net is, it cannot processs XML document created by coldfusion. To return XML to dot net, convert into string format (XMLvariable.Tostring)

param of HTTP request should be
<cfhttpparam type="Body" value="#trim(soap).ToString#" name="FileContent"/>

Manish
  • 1