Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
80571members
346458posts

Call to BearerToken.ObtainToken() causes an exception

mike_meirovitz
Commander
Commander
0 Likes
5
286

Call to BearerToken.ObtainToken() causes an exception

Hi,

 

We are using a SmartConnector end-point and we call the  BearerToken.ObtainToken() API from our code. See the code below.

When we call this API we see an exception in the SmartConnector log file. See below and attached.

 

public static int ObtainBearerToken ()
{
_bearerToken = null;
try
{
// Obtain Token
Uri uri = new Uri(Settings.m_strURL);
_log.InfoFormat("ObtainBearerToken uri = '{0}', user = '{1}', pass = '{2}'", uri.ToString(), Settings.m_strUser, Settings.m_strPassword);
_bearerToken = BearerToken.ObtainToken(uri, Settings.m_strUser, Settings.m_strPassword, "GetToken");
if (_bearerToken == null)
{
_log.ErrorFormat("ObtainBearerToken fail, token is empty or null");
return -4; // invalid token
}
_log.InfoFormat("ObtainBearerToken pass, token = '{0}'", _bearerToken.ToString());
return 0;
}
catch (Exception ex)
{
_log.ErrorFormat("ObtainBearerToken, Exception, msg = '{0}'", ex.Message);
return -4;
}
}

 

2022-04-10 13:19:19.9006,Debug,EwsConsume,<no principal>,GetWebServiceInformation,c309cc0a-1c53-4f5f-85a0-5c95ad6d8b4b,CommunicationException Handler,{"ClassName":"System.ServiceModel.EndpointNotFoundException","Message":"There was no endpoint listening at https://10.0.0.19/EcoStruxure/DataExchange that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.","Data":null,"InnerException":{"ClassName":"System.Net.WebException","Message":"Unable to connect to the remote server","Data":null,"InnerException":{"NativeErrorCode":10060,"ClassName":"System.Net.Sockets.SocketException","Message":"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nDoConnect\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Sockets.Socket\nVoid DoConnect(System.Net.EndPoint, System.Net.SocketAddress)","HResult":-2147467259,"Source":"System","WatsonBuckets":null},"HelpURL":null,"StackTraceString":" at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)\r\n at System.Net.HttpWebRequest.GetRequestStream()\r\n at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nGetRequestStream\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.HttpWebRequest\nSystem.IO.Stream GetRequestStream(System.Net.TransportContext ByRef)","HResult":-2146233079,"Source":"System","WatsonBuckets":null},"HelpURL":null,"StackTraceString":" at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n at Ews.Client.IDataExchange.GetWebServiceInformation(GetWebServiceInformationRequest1 request)\r\n at Ews.Client.DataExchangeClient.Ews.Client.IDataExchange.GetWebServiceInformation(GetWebServiceInformationRequest1 request)\r\n at Ews.Client.DataExchangeClient.GetWebServiceInformation(GetWebServiceInformationRequest request)\r\n at Ews.Client.EwsClient.ExecuteAndLogCall[TRequest,TResponse](String methodName, TRequest request, Func`2 methodToLog, Boolean includeMetadata)","RemoteStackTraceString":"\r\nServer stack trace: \r\n at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()\r\n at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n","RemoteStackIndex":1,"ExceptionMethod":"8\nHandleReturnMessage\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Runtime.Remoting.Proxies.RealProxy\nVoid HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage)","HResult":-2146233087,"Source":"mscorlib","WatsonBuckets":null},{"ClassName":"System.Net.WebException","Message":"Unable to connect to the remote server","Data":null,"InnerException":{"NativeErrorCode":10060,"ClassName":"System.Net.Sockets.SocketException","Message":"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nDoConnect\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.Sockets.Socket\nVoid DoConnect(System.Net.EndPoint, System.Net.SocketAddress)","HResult":-2147467259,"Source":"System","WatsonBuckets":null},"HelpURL":null,"StackTraceString":" at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)\r\n at System.Net.HttpWebRequest.GetRequestStream()\r\n at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nGetRequestStream\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Net.HttpWebRequest\nSystem.IO.Stream GetRequestStream(System.Net.TransportContext ByRef)","HResult":-2146233079,"Source":"System","WatsonBuckets":null},,,
2022-04-10 13:19:19.9006,Error,EwsConsume,<no principal>,There was no endpoint listening at https://10.0.0.19/EcoStruxure/DataExchange that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.0.0.19:443

Server stack trace:
at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Ews.Client.IDataExchange.GetWebServiceInformation(GetWebServiceInformationRequest1 request)
at Ews.Client.DataExchangeClient.Ews.Client.IDataExchange.GetWebServiceInformation(GetWebServiceInformationRequest1 request)
at Ews.Client.DataExchangeClient.GetWebServiceInformation(GetWebServiceInformationRequest request)
at Ews.Client.EwsClient.ExecuteAndLogCall[TRequest,TResponse](String methodName, TRequest request, Func`2 methodToLog, Boolean includeMetadata)
,["GetWebServiceInformation","c309cc0a-1c53-4f5f-85a0-5c95ad6d8b4b"],
2022-04-10 13:19:19.9006,Debug,Service,<no principal>,ClientPool.CheckOutConnection for http://127.0.0.1:8019/EcoStruxure/DataExchange,
2022-04-10 13:19:19.9006,Error,Processor,<no principal>,There was no endpoint listening at https://10.0.0.19/EcoStruxure/DataExchange that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.0.0.19:443

Server stack trace:
at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Ews.Client.IDataExchange.GetWebServiceInformation(GetWebServiceInformationRequest1 request)
at Ews.Client.DataExchangeClient.Ews.Client.IDataExchange.GetWebServiceInformation(GetWebServiceInformationRequest1 request)
at Ews.Client.DataExchangeClient.GetWebServiceInformation(GetWebServiceInformationRequest request)
at Ews.Client.EwsClient.ExecuteAndLogCall[TRequest,TResponse](String methodName, TRequest request, Func`2 methodToLog, Boolean includeMetadata)
at Ews.Client.EwsClient.ExecuteAndLogCall[TRequest,TResponse](String methodName, TRequest request, Func`2 methodToLog)
at Ews.Client.EwsClient.get_EwsVersionImplemented()
at Ews.Client.EwsClient..ctor(EwsSecurity credentials, String address, EwsBindingConfig bindingConfig, Nullable`1 compatibilityVersion)
at Ews.Client.EwsClient..ctor(IEndpoint endpoint, Nullable`1 compatibilityVersion)
at Mongoose.Service.Cache.CachedEwsClient..ctor(String poolKey, IEndpoint endpoint)
at Mongoose.Service.Cache.EwsClientPool.CreateNewInstance(String poolKey, IEndpoint endpoint)
at Mongoose.Service.Cache.ClientPool`3.<>c__DisplayClass5_0.<CheckOutConnection>b__0()
at Mongoose.Service.Cache.ThreadSafeDisposableBase.ThreadSafeCall[T](Func`1 callback)
at Mongoose.Service.Cache.ClientPool`3.CheckOutConnection(TEndpoint endpoint)
at Mongoose.Service.Cache.ManagedEwsClient.ManageCall[T](IEndpoint endpoint, Func`2 method, Nullable`1 callVersion)
at Mongoose.Service.Cache.ManagedEwsClient.GetAlarmEvents(IEndpoint endpoint, Nullable`1 priorityFrom, Nullable`1 priorityTo, String moreDataRef, String[] types, Nullable`1 callVersion)
at Mongoose.Process.Ews.AlarmItemReader.ReadData()
,[],

 

Any idea what causes the exception?

 

Thank you.

 

Mike

 

Attachments
Tags (1)
5 Replies 5
ardak
Commander Commander
Commander
0 Likes
4
283

Re: Call to BearerToken.ObtainToken() causes an exception

Hi,

 

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.0.0.19:443

 

Is there a EWS enabled EBO server configured to listen to at http://10.0.0.19:443/EcoStruxure/DataExchange?

Tags (1)
mike_meirovitz
Commander
Commander
0 Likes
3
273

Re: Call to BearerToken.ObtainToken() causes an exception

Hi,

 

We use HTTP URL not HTTPS. 

Our IP address was changed from 10.0.0.19:8019 to 10.0.0.18:8019. Why does SmartConnector tries to connect to the HTTPS URL instead of HTTP URL?

 

In any case, SmartConnector should not crash...

 

Thank you.

 

Mike

Tags (1)
ardak
Commander Commander
Commander
0 Likes
0
257

Re: Call to BearerToken.ObtainToken() causes an exception

Hello,

 

Please restart the service and post screenshots of all your REST endpoint configurations.

 

BR

Armend

Tags (1)
SteveGregory
Commander Commander
Commander
0 Likes
1
196

Re: Call to BearerToken.ObtainToken() causes an exception

Hi Mike,

 

EBO is configured to redirect all HTTP requests to HTTPS by default. You need to uncheck this in the EBO configuration. You may have done this already but it usually catches people out when creating a HTTP endpoint.

Tags (1)
mike_meirovitz
Commander
Commander
0 Likes
0
191

Re: Call to BearerToken.ObtainToken() causes an exception

Hi Steve,

 

Thanks. This property is unchecked in the EBO.

 

Mike

Tags (1)