Solved

C# to CFML - EWS API create appointment

Posted on 2014-03-29
15
710 Views
Last Modified: 2014-05-06
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
0
Comment
Question by:lanterv
  • 7
  • 6
  • 2
15 Comments
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 250 total points
Comment Utility
no points .. I haven't used EWS but can see your code leaves out some of the recommendations you got on another site:

Appointment appointment = new Appointment(_service);

The c# code "new Appointment(...)" just means is call init() with whatever parameters are shown. You forgot to pass in the service object into init():

             <cfset appointment.init( service )>  <=== service object created in line 1

java.lang.NoSuchFieldException: SETSTART

That's telling you there is no property named "SetStart".  Meaning you CAN'T set the property value like this:

          <cfset appointment.ThePropertyName = "...the value">

Instead you must call a method of the object. A method is like a function. Call function name with parenthesis and pass in the value. From your other thread:

         appointment.setStart( StartDateTime );

To find out other method names, cfdump the object and look for "setPropertyName", ie setStart, etc...

Good luck!
0
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 250 total points
Comment Utility
c# uses a lot of the .net framework where ColdFusion does not.. There is not a 1:1 relationship between the two. I would not use coldfusion for something like this, you can get a visual studio express and then code it in c# instead. Cold fusion doesn't create executables but objects that are interpreted by the cold fusion interpreter and having this work with exchange is near impossible.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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.
0
 

Author Comment

by:lanterv
Comment Utility
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.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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" )>
     .....
0
 

Author Comment

by:lanterv
Comment Utility
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.
0
 

Author Comment

by:lanterv
Comment Utility
_agx_:  I couldn't figure out ;

 , "path.to.ClassName"
0
Want to promote your upcoming event?

Is your company attending an event or exhibiting at a trade show soon? Are you speaking at a conference? Spread the word by using a promotional banner in your email signature. This will ensure your organization’s most important contacts are in the know.

 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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" )>
0
 

Author Comment

by:lanterv
Comment Utility
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".
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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?
0
 

Author Comment

by:lanterv
Comment Utility
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.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
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.
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
(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.
0
 

Author Closing Comment

by:lanterv
Comment Utility
Excellent attempts to help solve the problem.  But, I just couldn't handle it.  This post should probably be deleted.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now