Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error code:0 #62

Closed
Gabsao opened this issue Jun 4, 2016 · 8 comments
Closed

error code:0 #62

Gabsao opened this issue Jun 4, 2016 · 8 comments

Comments

@Gabsao
Copy link

Gabsao commented Jun 4, 2016

Hello everyone,

I'm trying to connect to my exchange server (Azure VM + exchange server 2016 + but without autodiscover) with the following code:

`var ews = require('ews-javascript-api');
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016);
exch.Credentials = new ews.ExchangeCredentials("domain\login", "password");
exch.Url = new ews.Uri("https://XXXXX.cloudapp.net/EWS/Exchange.asmx"); 

var attendee =[ new ews.AttendeeInfo("login@XXXX.local")];
var timeWindow = new ews.TimeWindow(ews.DateTime.Now, new ews.DateTime(ews.DateTime.Now.TotalMilliSeconds + ews.TimeSpan.FromHours(48).asMilliseconds())); 
exch.GetUserAvailability(attendee, timeWindow, ews.AvailabilityData.FreeBusyAndSuggestions)
.then(function (availabilityResponse) {
  //do what you want with user availability
    console.log(availabilityResponse)
}, function (errors) {
  //log errors or do something with errors
    console.log(errors)
});`

The Ews request is the following :

`sending ews request
{ url: �[32m'https://XXXX.cloudapp.net/EWS/Exchange.asmx'�[39m,
  headers: 
   { �[32m'Content-Type'�[39m: �[32m'text/xml; charset=utf-8'�[39m,
     Accept: �[32m'text/xml'�[39m,
     Authorization: �[32m'Basic QkXXXXXXXXXXXXXXXXXXXXdXIwMQ=='�[39m },
  type: �[32m'POST'�[39m,
  data: �[32m'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Header><t:RequestServerVersion Version="Exchange2016"></t:RequestServerVersion><t:TimeZoneContext><t:TimeZoneDefinition Name="UTC" Id="UTC"></t:TimeZoneDefinition></t:TimeZoneContext></soap:Header><soap:Body><m:GetUserAvailabilityRequest><m:MailboxDataArray><t:MailboxData><t:Email><t:Address>login@XXXX.local</t:Address></t:Email><t:AttendeeType>Required</t:AttendeeType><t:ExcludeConflicts>false</t:ExcludeConflicts></t:MailboxData></m:MailboxDataArray><t:FreeBusyViewOptions><t:TimeWindow><t:StartTime>2016-06-04T00:00:00</t:StartTime><t:EndTime>2016-06-06T00:00:00</t:EndTime></t:TimeWindow><t:MergedFreeBusyIntervalInMinutes>30</t:MergedFreeBusyIntervalInMinutes><t:RequestedView>Detailed</t:RequestedView></t:FreeBusyViewOptions><t:SuggestionsViewOptions><t:GoodThreshold>25</t:GoodThreshold><t:MaximumResultsByDay>10</t:MaximumResultsByDay><t:MaximumNonWorkHourResultsByDay>0</t:MaximumNonWorkHourResultsByDay><t:MeetingDurationInMinutes>60</t:MeetingDurationInMinutes><t:MinimumSuggestionQuality>Fair</t:MinimumSuggestionQuality><t:DetailedSuggestionsWindow><t:StartTime>2016-06-04T00:00:00</t:StartTime><t:EndTime>2016-06-06T00:00:00</t:EndTime></t:DetailedSuggestionsWindow></t:SuggestionsViewOptions></m:GetUserAvailabilityRequest></soap:Body></soap:Envelope>'�[39m }
`

And i got the following error :

Error in calling service, error code:0

Am I doing something wrong?? Or maybe the server is not configured properly??

Cheers,

@gautamsi
Copy link
Owner

gautamsi commented Jun 4, 2016

You may not have "Basic Authentication" enabled on ews virtual directory, it is not enabled by default. you have to enable this after configuring server.

following command help enable basic authentication.

Set-WebServicesVirtualDirectory -Identity Contoso\EWS* -BasicAuthentication $true

make sure you know what you are doing before running above script, exposing basic auth without SSL may expose your credential to wild.

I have not tested untrusted certificate with ews-javascript-api you can do certain node hack or just trust the self signed certificate on your client machine where you are testing this.

@gautamsi
Copy link
Owner

did you test this?

@guderkar
Copy link

Hi I have the exact same problem. I belive it is caused by not trusting server cert. I also tried C++ api and I had problem with certificate but there was an option to disable certificate check and it works. I don't know how to disable certification check in this api.

@gautamsi
Copy link
Owner

try this process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; from stack overflow

@guderkar
Copy link

Thanks it works now!

@guderkar
Copy link

I have one more question. How can I make the script work when I open index.html in browser. I tried browserify but no luck.

@gautamsi
Copy link
Owner

browser has XHR cross site limitation, Exchange does not support HTTP OPTION verb, no point using browser. you can use it in nw.js or in ElectronJS projects as npm module

@gautamsi
Copy link
Owner

@guderkar see #190 fro browser specific detail, you need to disable CORS if you want to test in browser. works in Electron's renderer process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants