Link to home
Start Free TrialLog in
Avatar of digitalwise
digitalwise

asked on

C# script to Coldfusion

We are connecting to a new vendor's webservice and were given sample code in c# which is a little rusty for me.

var broker = new Broker(); var c = broker.OrderInitialize(); 
c.RequiredInformation.ApplicationId = “applicationID”; 
c.RequiredInformation.ApplicationPassword = “applicationPwd”; 
c.RequiredInformation.TransPaymentType = “CC-PURCHASE”; 
c.RequiredInformation.Total = 20.00 
c.OrderDetails.OrderId = order.OrderId.ToString();
response.redirect(https://url/Payment.aspx”?tokenId=”+ broker.GetToken(c));

Open in new window


I am trying to convert it over to CF since that is what the client's platform is.    I thought creating an array would work but I am clearly missing something big.

<cfset objToken = {
    c.RequiredInformation.ApplicationId = "#application.yorkaid#",
    c.RequiredInformation.ApplicationPassword = "#application.yorkaad#",
    c.RequiredInformation.TransPaymentType = "CC-PURCHASE",
	c.RequiredInformation.Total = qryOrder.OrderTotal,
	c.OrderDetails.OrderId = Session.Registration.OrderID
    } />


    <CFLOCATION URL="url/Payment.aspx?tokenID=#objToken.GetToken(c)#" addtoken="no">

Open in new window


I know I don't have c set - OrderInitialize didn't seem to be a c# command...
Avatar of _agx_
_agx_
Flag of United States of America image

var broker = new Broker();
var c = broker.OrderInitialize();

Looks like they're creating an instance of some custom class, ie "Broker", and OrderInitialize() is a method of that class.  Are you also creating an instance of the custom class in CF, or are you reconstructing all of the logic in cfml?
Avatar of digitalwise
digitalwise

ASKER

I was trying to redo it all in cfml but I can use CFOBJECT to create a class but I am not sure what else i need to do...
Well it sounds like this "Broker" is a custom class.  Without seeing the actual code for that class, I don't know whether it's simpler to load the DLL and create instances of it -OR- rewrite the C# logic in CFML. All depends on what Broker.GetToken() and Broker.OrderInitialize() actually do (which I can't see :-)
So they provide me with a URL that they have labeled as Reference XML Webservice (QA).    Would a cfhttp call to that somehow start the ability to consume their webservice?  I guess I am just used to web services where I call it, send my information and then use their response.   This is package up my stuff and send it to their website in a redirect where the customer does their stuff and then comes back to us doesn't make sense.
Ooh.. if it's a web service, maybe those classes are created automatically from the WSDL, sort of like what createObject("webservice") does.  

If you try calling the web service with ?wsdl and dump the object, do you see any methods like OrderInitialize and GetToken()?

      <cfscript>
       obj = createObject("webservice", "https://theurl?wsdl");
       writeDump(obj);
      </cfscript>

EDIT:
cfhttp call to that somehow start the ability to consume their webservice

Yes, most likely.  However, I'd do the above first to confirm. Then figure out what info to pass and how.
Nope - that doesn't work - says unable to read so clearly not set up as wsdl...   I will wait until the dev guy is back inhouse tomorrow to see what the heck he missed sending me
Sounds like a good idea.
So by accident I clicked in a link the reference guide and was brought to a page about creating the service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe https://theirurl/Broker.svc?wsdl

You can also access the service description as a single file:

https://theirURL/Broker.svc?singleWsdl (which brings up XML)

Neither of which actually works with the createobject

then

class Test
{
    static void Main()
    {
        PaymentServiceClient client = new PaymentServiceClient();

        // Use the 'client' variable to call operations on the service.

        // Always close the client.
        client.Close();
    }
}

Open in new window

EDIT:
1. What's the exact error message from createObject?
2. Can you view it in a browser?
https://theirurl/Broker.svc?wsdl
3. You could also try using SOAPUI, to generate the xml needed to call it from cfhttp
4.  If you're using CF11 I believe it defaults to Axis 2. Try setting the call to use Axis 1:

  <cfscript>
        // only refresh once, ie refreshwsdl=true
      obj = createObject("webservice"
      , "https://theirurl/Broker.svc?wsdl"
      , {wsversion="1",refreshwsdl="true"});
      writeDump(obj);
  </cfscript>
1.    So apparently it is a CF8 issue because locally on CF11 it works (yes - I know - we are in the process of upgrading) - we have been using CFX_HTTP5 in the meantime...    The error on CF8 is Error: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated.    It does work on CF11... So will I be able to use CFX_HTTP5 to work around this?    I guess i will need to play with it.
2.   Yes
If it's just a standard web service, almost certainly yes.  Download SoapUI and plug in the URL to see what XML you need to supply.  

If it works under CF11, looking at the cfdump might help as well, since it's sometimes a little easier to follow than web service XML.
>> javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

... though since it's an SSL problem,  I'd try importing the certificate into the keystore.  See if that resolves it. Then you could use cfhttp or createObject("webservice"). Since it sounds like you probably can use CFX_HTTP5 either way, it's not critical, but it certainly wouldn't hurt to have the other options.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I imported the cert to the keystore and get Variable WRITEDUMP is undefined.   So no more issue with the connection but...
So am I wrapping that in cfscript??  Sorry - not completely clear on the steps...
Well it should always be defined, unless it's throwing a different error now, one not displayed on screen.  Check the error logs.

For grins, try the above under CF11, just to verify orderInitialize() does work with createObject.

Don't forget to try SoapUI too. If there's a problem with the web service under CF8, you may end up having to go the SOAP + cfhttp route.
order = ws.orderInitialize();
          writeDump( order );
          token = ws.getToken(order);

give me ws is not defined
Sorry, "ws" is a shortcut for whatever variable name you used for the web service object, ie

      ws = createObject("webservice", "https://theirurl/Broker.svc?wsdl");
I got it.   I am getting bad credentials but it is working on cf11   do you know why I get
 Variable WRITEDUMP is undefined on cf8?
Not sure.  Could be a fatal exception.  Those don't always display on screen. Often they're only in the log files, so I'd check there first.
Ah no - WriteDump - was CF9 and above.   But I am in business now...  Thank you so much!
Awesome as always!!
Oops, my bad.  Missed the part about it being Variable WRITEDUMP undefined.  Glad it worked out, despite that :-)