The remote server returned an error 401 unauthorized exchange

Hello,
  • Remove From My Forums
  • Question

  • Hello,

    I am trying to create appointment from Exchange Web Service, If I am trying to login to exchange server from URL then its working and allowing me to login to my exchange server but if I am trying to connect from my C# application then I am getting this error «The
    request failed. The remote server returned an error: (401) Unauthorized.»

    My current code is as below:

    ExchangeService service = new ExchangeService();
    service.Credentials = new WebCredentials("XXXusername", "pwd", "exchange.domain.com");
    
    service.Url = new Uri("https://exchange.domain.com/EWS/Exchange.asmx"); 
    Appointment appointment = new Appointment(service);
    appointment.Subject = "Status Meeting";
    appointment.Body = "The purpose of this meeting is to discuss status.";
    appointment.Start = new DateTime(2017, 1, 30, 9, 0, 0);
    appointment.End = appointment.Start.AddHours(2);
    appointment.Location = "Conf Room";
    appointment.RequiredAttendees.Add("xyz@domain.com");
    appointment.Save(SendInvitationsMode.SendToNone);

    If I am trying to login from url and its also working fine.
    exchange.domain.com
    username — XXXusername
    pwd — «pwd»

    Also I have tried to login web service from URL and its work for me.

    Please anyone suggest what’s the wrong with C# code and how I can make working it.

    Thanks.

Answers

  • You credentials aren’t specified correctly you should use either downlevel format which is domainusername which would be

    service.Credentials = new WebCredentials("XXXusername", "pwd");

    (Note you don’t specify the domain as you have already included it in the downlevel format)

    or use

    service.Credentials = new WebCredentials("username", "pwd","XXX");

    (Where XXX is the NetBIOS domain name not the FQDN like you have used) this is recommended method because of potential issue with UPN suffixes

    https://support.microsoft.com/en-us/help/2933452/-401-unauthorized-error-when-you-use-an-ews-application-to-impersonate-a-user-in-office365-dedicated-itar

    or use the Active Directory User Principal name which includes the domain name eg

    service.Credentials = new WebCredentials("username@upndomain.com", "pwd");

    Cheers
    Glen

    • Marked as answer by

      Tuesday, January 31, 2017 5:49 PM

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


Closed

senneko opened this issue

Dec 30, 2015

· 6 comments

Comments

@senneko

Hi. I’ve the next issue:
The request failed. The remote server returned an error: (401) Unauthorized.

I’m trying to send an appointment but when the process ends (appointment.save()) I have this problem.

I’m trying to connect the service as follows:

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        ExchangeCredentials credentials =  WebCredentials(user, pass, domain);
        service.setCredentials(credentials);
        service.setUrl(new URI("https://XXXXXXX/ews/exchange.asmx"));

Somebody knows how to fix it? Thanks.

@serious6

try connecting with the same credentials and url using the ews-editor

@senneko

I have one problem. The program is in an environment where only the administrator has access. Therefore I can not perform the test with the tool mentioned.

Is there any other way to solve this problem locally?

@serious6

The reason I suggested this tool is to check on your credentials or the provided URL as the error you reported might have its origin there. This API is about requests and responses to an exchange Server so if you dont have your exchange Server configured locally there is nothing to test with. Maybe provide some additional information about your environment.

@avromf

To test general connectivity issues to an Exchange Server you can also try this:
https://testconnectivity.microsoft.com/
Select «Service Account Access (Developers)» under «Microsoft Exchange Web Services Connectivity Tests».

@senneko

I found the problem. the domain that was using was wrong. I change the domain and effectively the problem of authorization was eliminated.
Thank you for your help.

@amolthorat1991

Hi,
I tried to connect to exchange mail server using the ews service provided but I am getting the following issue. Can you please help me on this..

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. The remote server returned an error: (401)Unauthorized
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.internalCreateItems(ExchangeService.java:598)
at microsoft.exchange.webservices.data.core.ExchangeService.createItem(ExchangeService.java:657)
at microsoft.exchange.webservices.data.core.service.item.Item.internalCreate(Item.java:245)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.internalSend(EmailMessage.java:147)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.send(EmailMessage.java:258)
at mailservice.MSExchangeEmailService.main(MSExchangeEmailService.java:211)
Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The remote server returned an error: (401)Unauthorized
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:651)
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62)
… 7 more
Caused by: microsoft.exchange.webservices.data.core.exception.http.HttpErrorException: The remote server returned an error: (401)Unauthorized
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:725)
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:646)
… 8 more


Aftab Alam

Read time 6 minutes

Office 365 is the favorite destination of the majority of business organizations when they think about a suitable cloud platform. It has become a dominant player in the cloud business and businesses are migrating their data at a rapid speed. However, there are multiple precautions which you should take care while migrating the data; otherwise, there can be some unwanted errors.

In this article, we will go through one significant error which does not even let the migration started. The error is following:

The request failed. The remote server returned an error: (401) Unauthorized.

bussinesman

Instant Solution

To migrate your Office 365/Microsoft 365 data securely, try Kernel Office 365 Migration tool. It is a quick and accurate tool for all Office 365 Migration task.

If you are facing this kind of error, then there may be multiple reasons behind this issue

  1. The user ID is different than the UPN (User Principal Name).

    If the Office 365 account which you are using is different from the UPN from the Active Directory, then you will have to face the error.

  2. MFA (Multi-Factor Authentication) is enabled for Office 365.

    If the Office 365 has multi-factor authentication enabled for the account, this it is not easy for a manual method to access the mailbox easily.

  3. The Username and Password have incorrect spelling.

    The spelling of the username and password of the Office 365 is not correct.

  4. The domain of Office 365 is not registered with the DNS of the Microsoft.

    Many times, the user creates an Office 365 account and try to start the migration instantly. Then the error may occur, because the domain of the Office 365 may not be registered with the Microsoft DNS.

    If you are facing this error, then you may try to use the following solutions to rectify the problem:

    1. Update the Administrator credentials.
    2. Edit the Migration Endpoint in the Exchange Admin Center. Try to check complete detail of the batch migration and edit the information.
    3. If the Password of the Administrator account is too complicated, then reset it.
    4. Assign the Global Administrator credentials to the Office 365 account.
    5. Choose a different Office 365 account for the migration.

Professional Solution

After making all the appropriate changes in the Office 365 account, the error should be removed, and the migration should also be smooth. But if you still are facing the same error due to UPN settings and there is no manual method to solve the problem, then use a professional tool which can bypass all the technicalities and perform the migration on your terms. Kernel Office 365 Migration is the best-suited migration software which can access the email ID along with the UPN ID and complete the migration. Here is the brief procedure for Office 365 data migration –

  1. After successful installation, run the software and click the Add button to select the source.
    select the source
  2. Input the credentials of the source account and click the Add button. Single Mailbox/Office 365 Group option is selected by default. To migrate multiple mailboxes, select the second option.
    Input the credentials
  3. The tool will enlist all the accounts associated with the Administrator account. You can select/deselect the account quickly. Click Add.
    Click Add
  4. In the next windows, you need to map both source and destination account. Click the Set Filter and Migrate button.
    Set Filter and Migrate button
  5. The following window will let you select the desired type of item like Mailbox, Public Folder, and Archive Mailbox. You can make your selection from the drop-down menu and then click the Migrate button.
    select the desired type of item
  6. The Filter Selection window has some best-suited filters options to select only the essential data to migrate and leave the rest.
    Date Filter – Input a date range.
    Item Type Filter – Check various options among Email, Journal, Task, Contacts, Calendar/Appointment.
    Exclude Deleted Folders – Stop the deleted folders from migration
    Exclude empty folder – Stop empty folders from migration.
    Save all hierarchy in a new folder – Provide a name of the folder, and all the data will be saved in the folder.
    Set operation timeout – Set the time limit for the migration of each item.
    Skip previously migrated items – Stop already migrated items from migration.
    Finally, click I am OK, Start Migration.
    click I am OK, Start Migration
  7. After a successful migration, the tool will provide you a message that migration is complete. Click OK.
    Click OK
  8. To get a comprehensive migration report, click the option Save report to CSV.
    click the option Save report to CSV

After completing the migration procedure, click OK.

Conclusion

When you are using this KernelApps tool, you will not have to face errors like 401 – Unauthorized Access. It is a flexible tool which supports the Office 365 environment and reduces the network complexities. For much assistance, you can contact the technical team which is available to you 24*7.

Video

More Information

  • Office 365 Migration Stuck on Syncing/Completing
  • Avoid these Most Common Office 365 Deployment Mistakes
  • Office 365 Shared Mailbox not Showing in Outlook
  • Common Office 365 Problems and their Solutions

    Introduction

    This document describes identification and remediation of Expressway Connector with the error status Exchange server HTTP error code 401 from the GUI.

    Prerequisites

    Requirements

    — Webex Control Hub Organization.

    — Hybrid Calendar with Exchange service

    — Expressway Connector (X12.5 at a minimum for new deployments)

    https://help.webex.com/en-us/article/ruyceab

    Components Used

    The information in this document is based on these software and hardware versions:

    • Hybrid Calendar activated. In this guide, use Hybrid Calendar with Exchange.
    • Exchange Server 2019 Standard.
    • Expressway-C X14.0.5.

    The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, ensure that you understand the potential impact of any command.

    Symptom

    Expressway-C GUI

    Navigate to Applications > Hybrid Services > Calendar Service > Calendar Connector Status. The Collaboration On-Premises displays message status error: Exchange server http error code 401.

    Screen Shot 2022-02-21 at 10.03.18

    Troubleshoot

    The loggingsnapshot.txt file is needed to locate the timestamp of the error from the Expressway server. If no logs are collected, Diagnostic Logs are needed while the issue is replicated.

    Screen Shot 2022-02-21 at 10.03.51

    With the logs collected, extract the files and locate loggingsnapshot.txt file.

    diagnostic_log_ccnp-expressway-hybrid1_2022-02-21_16 03 39.tar.gz

    Search for this output:

    2022-02-21T10:00:15.018-06:00 localhost UTCTime="2022-02-21 16:00:15,017" Module="hybridservices.c_cal" Level="ERROR" Thread="ews-recovery-2" TrackingId="" Detail="checkServiceEntityConnectivity() threw ServiceRequest exception. Root cause exception: microsoft.exchange.webservices.data.HttpErrorException: The remote server returned an error: (401)Unauthorized"

    (401)Unauthorized means the impersonation account password is invalid, possibly expired, or changed. 

    Confirm Imprersonation Account

    Verify that the impersonation account is able to access the user interface in Outlook on the web (formerly known as Outlook Web App). Confirm that the password is expired.

    Screen Shot 2022-04-04 at 21.45.50

    OWA URL:

     https://<IPv4_FQDN_MXS>/owa

    Solution

     Change the password of the account and update the Calendar Connector configuration to bring the Hybrid Calendar back to Operational. Make the change from the OWA portal or update the password from Active Directory if the account is synchronized from there (out of scpe for this document).

    Reset Mailbox Password via Exchange Admin Center (EAC)

    In order to have this option available these commands needs to be run from Exchange Management Shell.

    — Add-Pssnapin microsoft*
    — Install-CannedRbacRoles
    — Install-CannedRbacRoleAssignments

    Screen Shot 2022-04-04 at 21.11.32

    Enable the Reset Password option in the Exchange Admin Center.

    1. Log in to Exchange Admin Center, navigate to Permissions>Organization Management, and click Edit.
    2. In the Organization Management page, click + option under the Roles section (to add a new role).
    3. Select the Reset Password from the provided list, click the Add option, and then click Save.
    4. When the changes are saved, sign out from the Exchange Admin Center and log in again.

    To confirm if the role is properly activated, run the command:

    — Get-ManagementRole -id «Reset Password» | fl

    Screen Shot 2022-04-04 at 22.05.49

    Select a user mailbox, click Edit to view its properties, and find the Reset Password option.

    Screen Shot 2022-04-04 at 22.07.54

    Reset Mailbox Password via Exchange Management Shell

    It is possible to reset a password via CLI, however, the old password is required to run the command:

    Set-Mailbox -Identity "User" -OldPassword (ConvertTo-SecureString -string "OldPassword" -AsPlainText -Force) -NewPassword (ConvertTo-SecureString -string "NewPassword" -AsPlainText -Force)

    that is:

    Set-Mailbox -Identity "email address" -OldPassword (ConvertTo-SecureString -string "Webex4Ever" -AsPlainText -Force) -NewPassword (ConvertTo-SecureString -string "Webex4Ever&Ever" -AsPlainText -Force)

    Screen Shot 2022-04-04 at 22.15.48

    Validate the new Password from OWA

    The impersonation account is now able to access the user interface in Outlook on the web (formerly known as Outlook Web App) with the updated credentials.

    Screen Shot 2022-04-04 at 22.20.20

    Screen Shot 2022-04-04 at 22.21.02

    Update the Calendar Connector configuration

    From Applications > Hybrid Services > Calendar Service > Microsoft Exchange Configuration > Credentials; update the Service Account Password with the newest password.

    Screen Shot 2022-04-04 at 22.27.44

    Save the configuration at the bottom of the page.

    Screen Shot 2022-04-04 at 22.28.19

     Restart (Disable/Enable) the Calendar Connector to finish the process.

    Screen Shot 2022-04-04 at 22.30.18

    Screen Shot 2022-02-21 at 10.01.33

     The Calendar Connector service is back to Operational and Users are fully Activated.

    Screen Shot 2022-02-21 at 17.03.46

    Common Issues

    Unable to add Reset Password Roles to Organization Management.

    The delegation permissions have not been applied correctly to the Role Group. Run this command from Exchange server CMD.

    Setup /p

    Screen Shot 2022-04-04 at 22.38.16

    Screen Shot 2022-04-04 at 22.38.59

    Restart the Exchange server and attempt Reset Password again.

    References

    Deployment Guide for Cisco Webex Hybrid Calendar Service

    Supported Versions of Expressway for Webex Hybrid Services Connectors

    Resource Groups for Cisco Webex Hybrid Services

    Upgrade the Connector Host Expressway used for your Hybrid Services

    Hybrid Calendar Service Release Notes

    Automatic Upgrades for Hybrid Services Resources

    I came across the call to ‘https://mail.domain.com/EWS/mrsproxy.svc failed error while trying to move a mailbox from Exchange on-premise to Office 365.

    While the first line of the error message suggests a network connectivity issue in reaching my EWS endpoint, the full error message gave the bigger picture. 

    Error: The call to ‘https://mail.domain.com/EWS/mrsproxy.svc’ failed. Error details: The HTTP request is unauthorized with client authentication scheme ‘Negotiate’. The authentication header received from the server was ‘Negotiate,NTLM’. –> The remote server returned an error: (401) Unauthorized.. –> The HTTP request is unauthorized with client authentication scheme ‘Negotiate’. The authentication header received from the server was ‘Negotiate,NTLM’. –> The remote server returned an error: (401) Unauthorized.

    As it says in the error above, the server is treating it as an unauthorized connection, which lead me to the permissions.

    The issue was that the password for the account that was used in the migration endpoint was changed. I have seen instances where this kind of account gets disabled as part of the weekly maintenance scripts.

    The steps to fixing the issue is as follows.

    • Reset the password for the account used in setting up the migration endpoint (complex password ofcourse) and set it to never expire.
    • Login to the Office 365 portal and head to the Exchange Admin Centre.
    • Navigate to the ‘Migration’ tab and click on the “…” to bring up the Migration Endpoints.
    • Edit the endpoint in question and update the administrator credentials

    Once the migration endpoint was updated, the mailbox move to Office 365 was successful.

    Cloud Architect & Blogger with interests in Microsoft 365, Azure, AWS & PowerShell. I am active on Experts Exchange & TechNet forums and I am a technical author for SearchExchange. Follow me on Twitter, LinkedIn, or Facebook for the latest updates. For consultancy opportunities, drop me a line.

    Понравилась статья? Поделить с друзьями:
  • The remote server returned an error 400 bad request перевод
  • The remote machine reported the following error dameware
  • The remote desktop management service failed to start error code 0x88250001
  • The relevant error causing widget was column
  • The lord of the rings the battle for middle earth exception ошибка