web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How to fix Office 365 WS-Trust Authentication Deprecation error?

(0) ShareShare
ReportReport
Posted on by 5

We have a dynamics applications where we have integrated a Asp.net Web API to accomplish our custom business logic for Order and Quote entity. Currently the application uses user account and password credentials for authentication with Dataverse. But recently this authentication has been deprecated and that's why getting error from the Web API.

To resolve this, we have started to move our authentication procedure to OAuth. But we are getting a Object reference not set to an instance of an object.

 

Previous Code:

public sealed class ConnectionManager
{
    readonly OrganizationServiceProxy proxy;
    readonly OrganizationContext context;

    public ConnectionManager(ICrmConfiguration c)
    {

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        var crmCredentials = new ClientCredentials();

        crmCredentials.UserName.UserName = c.UserName;
        crmCredentials.UserName.Password = c.UserPassword;

        proxy = new OrganizationServiceProxy(new Uri(c.ServiceUri), null, crmCredentials, null)
        {
            Timeout = new TimeSpan(hours: 0, minutes: 5, seconds: 0)
        };

        proxy.EnableProxyTypes();

        context = new OrganizationContext(proxy)
        {
             MergeOption = MergeOption.PreserveChanges
        };

    }
}

OrganizationContext is generated from early bound generator tool where the code snippets is like below:

[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "9.0.0.9154")]
public partial class OrganizationContext : Microsoft.Xrm.Sdk.Client.OrganizationServiceContext
{

    /// <summary>
    /// Constructor.
    /// </summary>
    public OrganizationContext(Microsoft.Xrm.Sdk.IOrganizationService service) : base(service)
    {
    }

    /// <summary>
    /// Gets a binding to the set of all <see cref="CRMProxy.Model.Account"/> entities.
    /// </summary>
    public System.Linq.IQueryable<CRMProxy.Model.Account> AccountSet
    {
         get
         {
               return this.CreateQuery<CRMProxy.Model.Account>();
         }
    }

    ..

    ...

}

Current Code: To resolve the issue, we have changed ConnectionManager class like the following.

public sealed class ConnectionManager
{
    readonly OrganizationContext context;

    public ConnectionManager(ICrmConfiguration c)
    {

        var connectionString = "AuthType=OAuth;Username=xxx@xxxx.onmicrosoft.com;Password=xxxxx;Url=">xxxxx.crm.dynamics.com/.../58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto";

        CrmServiceClient crmConn = new CrmServiceClient(connectionString);
        var context= new OrganizationContext(crmConn);

        var p = context.SalesOrderSet.ToList(); // Getting Object reference not set to an instance of an object.

    }
}

AppID and RedirectUri are default one from the documentation. After changing the connection procedure, when we are retrieving data it is giving a Object reference not set to an instance of an object error. Maybe I am missing something. So we need your kind help.

Note: If am I posting it in the wrong forum, then please guide me to the exact one.

References:

    1. brianilland.me/.../

 

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: How to fix Office 365 WS-Trust Authentication Deprecation error?

    Hi,

    Before getting the context, please check if connection is success

    CrmServiceClient crmConn = new CrmServiceClient(connectionString);

    if(crmConn.IsReady)

    {

           var context= new OrganizationContext(crmConn);

           var p = context.SalesOrderSet.ToList(); // Getting Object reference not set to an instance of an object.

    }

    else

    {

    Console.WriteLine("Error:"+crmConn .LastCrmError);

    }

    You can download the console app from my github to connect to crm -

    github.com/.../WorkWithCsharp

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Protap Ghose Profile Picture
    5 on at
    RE: How to fix Office 365 WS-Trust Authentication Deprecation error?

    Hello Ketan,

    I tried the solution from a console application where the .NET framework version is 4.7.2 and the SDK assemblies are also up-to-date.  But still getting this error.

  • Suggested answer
    NODAL Profile Picture
    860 on at
    RE: How to fix Office 365 WS-Trust Authentication Deprecation error?

    Hi Protap,

    In additional to above changes make sure following things.

    1] Update .Net Framework of your application to 4.6.2 or later

    2] Use latest SDK assemblies.docs.microsoft.com/.../download-dynamics-365-sdk-v9

    Cheers,

    Ketan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
DAnny3211 Profile Picture

DAnny3211 134

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 106

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans