Link to home
Start Free TrialLog in
Avatar of lanterv
lanterv

asked on

C# to CFML - EWS API create appointment

I've been researching a problem I'm having creating an appointment on an Exchange server.  I seems to be coming down to creating an appointment object.  I have the following code;

<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeService" name="service">
<cfset service.init()>
<cfobject type="Java" class="microsoft.exchange.webservices.data.ExchangeVersion" name="version">
<cfset service.init(version.Exchange2007_SP1)>

<cfobject type="Java" class="microsoft.exchange.webservices.data.WebCredentials" name="credentials">
<cfset credentials.init("z@x.com","password")>
<cfset service.setCredentials(credentials) />
<cfobject type="Java" class="java.net.URI" name="uri">
<cfset uri.init("https://owa016.msoutlookonline.net/EWS/Exchange.asmx?wsdl")>
<cfset service.setUrl(uri) />

<cfobject type="Java" class="microsoft.exchange.webservices.data.Appointment" name="appointment">
<cfset appointment.init()>
<cfset appointment.Start = createDateTime(Year('2014/03/29'), Month('2014/03/29'), Day('2014/03/29'), Hour('09:00'), Minute('09:00'), 0)>
<cfset appointment.End = createDateTime(Year('2014/03/29'), Month('2014/03/29'), Day('2014/03/29'), Hour('10:00'), Minute('10:00'), 0)>
<cfset appointment.Subject("Dentist Appointment")>
<cfset appointment.Body = "The appointment is with Dr. Smith.">
<cfset appointment.IsReminderSet = false>
<cfset appointment.Save(SendInvitationsMode.SendToNone)>

Open in new window


I'm getting the following error;

Error Occurred While Processing Request
The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.
Null Pointers are another name for undefined values.

If I use .SetStart instead of .start I get;

java.lang.NoSuchFieldException: SETSTART

I'm guessing I don't have a legit appointment object.  The following seems to be the one line in all examples that I cannot convert to CFML;

Appointment appointment = new Appointment(_service);

CF9
EWS API 1.2
Exchange 2007
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
ASKER CERTIFIED SOLUTION
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
FYI: Actually, ColdFusion can load .net objects. CF runs on java but uses a 3rd party tool to access .net classes, called jnbridge.

That said, the code above appears to being using the java API for EWS, not the .net assemblies.  (Based on their other posts on another site, it sounds like there may be some sort of bug in the java API revolving around time zones?)  

If you have the .net assemblies for EWS, you could always also try using the C# api instead of the java one.  

(Edit) It might be a little easier to code this in a C# project directly, without the additional layer. However, whichever way you slice it, you'll still need to learn a bit about the EWS API and using C# and/or java classes first.
Avatar of lanterv
lanterv

ASKER

I'm down to the problem handling the timezone.  We are in the process of migrating our sites to CF10 and migrating to Exchange 2013.  I needed a workaround.  I'm looking at your suggestions.
I'm down to the problem handling the timezone

The comments on your other thread suggest there's a bug in the java api that's not easy to work around.  If you have the .net dll's for this, I'd suggest trying those instead. The syntax should be similar and you'll still use createObject() - just with different parameters:

     <cfset obj = createObject(".net"
                     , "path.to.ClassName"
                     , "c:/path/to/TheDotNetAssbemblyFiles.dll" )>
     .....
Avatar of lanterv

ASKER

DotNet Side does not seem to be running.

Ensure that the DotNet agent is running and you have provided the correct host and port information

After getting the above error I decided to download VS 2010 Express and dabble with writing C# code.

OMG what a headache!  I got it to create a meeting with one attendee ( same as the mailbox name) by hardcoding the email address and password.  When I tried to use UserData.EmailAddress = HttpContext.Current.Request.QueryString("EmailAddress"); I get

Error      1      The name 'HttpContext' does not exist in the current context      

and the same for UserData.
Avatar of lanterv

ASKER

_agx_:  I couldn't figure out ;

 , "path.to.ClassName"
DotNet Side does not seem to be running.

Yeah, the .net service has to be working before you can use createObject(.net).  Did you verify the service is running?  If yes, did you do a search for that error? There are a bunch of entries on that error, some version dependent. In my experience it tends to either work right out of the box or sometimes to you have to reinstall it.  

How to resolve error “DotNet Side does not seem to be running” with Coldfusion 901 on Windows

CF 9.02 brand new install getting "DotNet Side does not seem to be running" error

, "path.to.ClassName"

.NET (and java) classes are organized into packages (think folders/subfolders). For example:

/Microsoft.Exchange                  <=== top level folder 
   |--- WebServices                      <=== sub folder 
           |--- Data                           ..... 
                 |--- ExchangeService    <==== class name

Open in new window

When you use createObject() you need to tell CF the "path" to the class you're want to load.  You can find the path for each class in the API docs. For example if you're trying to create an ExchangeService object, the path is "Microsoft.Exchange.WebServices.Data.ExchangeService"

<cfset obj = createObject(".net"
                     , "Microsoft.Exchange.WebServices.Data.ExchangeService"
                     , "c:/path/to/TheDotNetAssbemblyFiles.dll" )>
Avatar of lanterv

ASKER

After uninstalling and re-installing CF .net, the jnbridge folder is missing.  So far it hasn't caused a problem that I'm aware of, but I can't follow the rest or the instructions for correcting the error "dotnet doesn't seems to be running".
It sounds like it didn't reinstall correctly.  Did you follow the instructions for your version of CF? They're similar, but there are slightly different issues for 9.01 v 9.02. Any errors during install? What do the log files say?
Avatar of lanterv

ASKER

There is no (efficient) way for me to get Coldfusion to set an appointment on Exchange 2007.  My only option is to upgrade to Exchange 2013.  This has been a giant PITA!  Thank you Adobe and thank you Microsoft.

And a sincere thank you to you who have made an effort to help.
Were you ever able to try using the C# classes on a dev box? The C# is probably a better bet since a) most examples are in C# b) there's not a lot of documentation on the java version which is makes it more frustrating/difficult to use and c) the java version seems to have missing/different functionality
Doctor my head hurts when I bang it on the wall..

Why don't you just bite the bullet and get one of the Visual studio express versions and then code it. They are free and supported and also the c# code examples will work for you.
(Edit)
Why don't you just bite the bullet and get one of the Visual studio express versions and then code it.

Guess you missed the previous comments, mentioning they tried that.

At this point I think it's down to either using createObject(".net") or duplicating the functionality in .net, though the end product still needs to be integrated w/CF. As I mentioned before, both require learning some .net/C# , no way around it.

I don't have access to an exchange server 2007. Otherwise, I'd try the examples myself and would be able to tell you one way or the other if it'll work w/Exchange 2007 and the c# dlls - from CF or VS. I assume the latter does, and that it is just a coding problem, but ... I've no way to verify it.

@David Johnson, CD - If you can offer any advice on setting up the equivalent functionality in VS/C#, I'm sure they'd appreciate the assist.
Avatar of lanterv

ASKER

Excellent attempts to help solve the problem.  But, I just couldn't handle it.  This post should probably be deleted.