WCF REST SOAP web service - unauthorized error - c#

I get this error. I have WCF REST SOAP web service thats supposed to fetch data from sharepoint list using sharepoint API and output it in json format. it works well on test server but not on iis production server.
System.Data.Services.Client.DataServiceQueryException: An error occurred while p
rocessing this request. ---> System.Data.Services.Client.DataServiceClientExcept
ion: Unauthorized
at System.Data.Services.Client.QueryResult.ExecuteQuery(DataServiceContext co
ntext)
at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServi
ceContext context, QueryComponents queryComponents)
--- End of inner exception stack trace ---
at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServi
ceContext context, QueryComponents queryComponents)
at System.Data.Services.Client.DataServiceQuery`1.Execute()
at System.Data.Services.Client.DataServiceQuery1.GetEnumerator()
at WCF_SOAP_REST_Service.Service.MapColumnValues_Events(IEnumerable1 items,
String language)
how to fix it?

Related

Getting "System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly." error while calling web api

In my application, there is a functionality to extract reports based on a date range. In the background, it is calling my Web API with authentication(A), which consists of api caller functionality using httpclient, which is calling another non-secured DMZ server API (B) and a DMZ API-caliing WCF service (C) to collect data from the database.
My problem is that whenever I select a large date range, I get the following error in my WebAPI (A).
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at LRAS.OrderServices.Core.Helpers.ApiCaller.d__4.MoveNext()
What I have tried: I have increased the httpclient timeout from 300 to 1000 seconds, but it is breaking nearly every minute.
You can try several methods:
1.Configure the service point security protocol and select the SecurityProtocolType that suits you (Tls12, Ssl3, Tls, Tls11).
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
C# System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send
2.Set the ConnectionClose property of HttpClient.
_client.DefaultRequestHeaders.ConnectionClose = true;
HttpClient throwing "An error occurred while sending the request."
3.Try to hold the request long enough for it to complete normally and receive a valid response.
_client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
_client.DefaultRequestHeaders.Add("Keep-Alive", "3600");
.NET HttpClient - An existing connection was forcibly closed by the remote host

Can't connect to Azure Blob Storage from App Service

I am trying to connect to a Azure Blob Storage account from an App Service hosted within the same location and in the same resource group. However when attempting to create a container during startup I get the following exception:
System.AggregateException: One or more errors occurred. (An error
occurred while sending the request.) --->
Microsoft.WindowsAzure.Storage.StorageException: An error occurred
while sending the request. ---> System.Net.Http.HttpRequestException:
An error occurred while sending the request. --->
System.Net.Http.WinHttpException: A connection with the server could
not be established
The inner exception is:
Microsoft.WindowsAzure.Storage.StorageException: An error occurred while sending the request. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: A connection with the server could not be established
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
at System.Net.Http.WinHttpHandler.d__105.MoveNext()
--- End of inner exception stack trace ---
I have double checked the account name, URL and access keys. I have also tried cycling the access keys to be sure. I have tried connecting to another storage account from the same app service and that also fails.
There are no app firewalls or VNets in place on either resource and I am at a loss as to what could be causing the issue.

EWS Api gives timeout and (503) Server Unavailable

I'm using the following code to get calendar appointments from my Office 365 account with EWS api's set (Microsoft.Exchange.WebServices 2.2.0):
ExchangeService service = new ExchangeService();
service.Credentials = new NetworkCredential(mail, password);
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
Folder DefaultCalendar = Folder.Bind(service, WellKnownFolderName.Calendar);
CalendarView calendarView = new CalendarView(fromDate, toDate);
FindItemsResults<Appointment> resultAppointments = Folder.FindAppointments(calendarView);
often the application crash with the following exceptions:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The
request failed. The operation has timed out --->
System.Net.WebException: The operation has timed out at
System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) --- End of inner exception stack trace --- at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&
request) at
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.CalendarFolder.Bind(ExchangeService
service, FolderId id)
or:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The
request failed. The remote server returned an error: (503) Server
Unavailable. ---> System.Net.WebException: The remote server returned
an error: (503) Server Unavailable. at
System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) --- End of inner exception stack trace --- at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&
request) at
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId
folderId, PropertySet propertySet) at
Microsoft.Exchange.WebServices.Data.CalendarFolder.Bind(ExchangeService
service, FolderId id)
or:
Microsoft.Exchange.WebServices.Data.ServiceRequestException: The
request failed. The underlying connection was closed: A connection
that was expected to be kept alive was closed by the server. --->
System.Net.WebException: The underlying connection was closed: A
connection that was expected to be kept alive was closed by the
server. at System.Net.HttpWebRequest.GetResponse() at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) --- End of inner exception stack trace --- at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest
request) at
Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest&
request) at
Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest1.Execute()
at
Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable1
parentFolderIds, SearchFilter searchFilter, String queryString,
ViewBase view, Grouping groupBy, ServiceErrorHandling
errorHandlingMode) at
Microsoft.Exchange.WebServices.Data.Folder.InternalFindItems[TItem](SearchFilter
searchFilter, ViewBase view, Grouping groupBy) at
Microsoft.Exchange.WebServices.Data.CalendarFolder.FindAppointments(CalendarView
view)
or:
The server cannot service this request right now. Try again later.
It seems that sometimes Office 365 services are unreachable or on throttling; I tried to try-catch my code, but the application still crash; I think because a new Thread is opened. How can I handle this issue?
The first place to start is to get the latest version of the EWS Managed API from Github https://github.com/OfficeDev/ews-managed-api . The version you using hasn't been update since 2015 which is when Microsoft stopped releasing compiled versions of that library. However the code has been updated with numerous bug fixes on GitHub
With the code your using I would suggest you always set the X-AnchorMailBox which can cause 503 and timeout issues see
https://blogs.msdn.microsoft.com/webdav_101/2015/05/11/best-practices-ews-authentication-and-access-issues/ (even if your not using Impersonation)
Depending on how much work your application is doing you may get throttled its important in that case to process the exception and retry. Also with Office365 mailboxes get moved around a fair bit on the back-end so it can be common to see period where the Mailbox is inaccessible during these moves
I tried to try-catch my code, but the application still crash; I think because a new Thread is opened. How can I handle this issue?
No it doesn't span a new thread you can check the source yourself on GitHub so you must have another issue with your exception handling.

Request timed out on IIS

I am creating a payroll application and i have to do processing of over 500 employees. When I run the application on my local machine, it would run the application and produce correct information. It would take close to 3-4 mins to complete the processing of data. When i deploy my application to IIS and try to run it, i would get the following error below:
Server Error in '/' Application.
Request timed out.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request timed out.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Request timed out.]
I tried changing the connection time out (seconds) to 600 in the advance setting for IIS for that particular Site but that didnt work. Any suggestion?
Try to change web.config parameter <httpRuntime executionTimeout="90"/>
90 - is default value in seconds
you need to set greater value

Autocomplete with jquery json. Internal server error 500?

Autocomplete with jquery json with c#:
The program works on local but not works on server.Why?
[WebMethod]
public List<string> GetAutoCompleteData(string prefixText)
{
...
here is the error:
Internal server error 500
and also this error:
Server Error in '/' Application.
Unknown web method GetAutoCompleteData. Parameter name: methodName
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Unknown web method
GetAutoCompleteData. Parameter name: methodName
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Unknown web method GetAutoCompleteData. Parameter
name: methodName]
System.Web.Script.Services.WebServiceData.GetMethodData(String
methodName) +539974
System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData
webServiceData, String methodName) +10
System.Web.Script.Services.RestHandler.CreateHandler(HttpContext
context) +159
System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext
context, String requestType, String url, String pathTranslated) +62
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext
context, String requestType, String url, String pathTranslated) +47
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execut
e()
+334 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.272
Ok, now we are getting somewhere.
If I understand this correctly, you have implemented a webmethod within your asp.net website in an asmx file (something that we are also doing in one of our products as well). In order for this to work properly in IIS (works fine in development environment), you will need to configure your IIS to allow .asmx pages (add a handler mapping). You can do this directly in the IIS config, or in your web.config.
Here is another question for reference:
ASMX service works on development server, returns 404 when deployed to IIS 7.5
Disregard bounty thing. Different question :)

Categories

Resources