Skip to main content

Notifications

Microsoft Dynamics CRM forum
Suggested answer

Object reference not set to an instance of an object web service

Posted on by 60

hello everyone

I'm trying to create a record in crm by web service. I know I have to create a connection string in my web service and it has no problem and when I'm debugging project it answers correctly.

But when I share my program on iis and its going to create record I get this error:

Object reference not set to an instance of an object

  • Maryam_m Profile Picture
    Maryam_m 60 on at
    RE: Object reference not set to an instance of an object web service

    I checked them and their ok. You know my code is answering during debug but on iis it cant answer

  • Amit Katariya007 Profile Picture
    Amit Katariya007 5,816 Moderator on at
    RE: Object reference not set to an instance of an object web service

    Hello,

    Please check below things for the troubleshoot this issue.

    1. So first please check if your are passing the correct parameter to the MSD server to get all the required information for establishment of the connection.

    2. This is most important thing please check the firewall settings for the server. Because most of the time your server's firewall will block this responses and because of that connection will not established. and after some time it will show this type of timeout error.

    Thank you,

    Amit Katariya

  • Amit Katariya007 Profile Picture
    Amit Katariya007 5,816 Moderator on at
    RE: Object reference not set to an instance of an object web service

    Hello Maryam,

    Is it hosted anywhere by the iis team. Like is it working on some server or user will run this web service by them selves?

    Thank you,

    Amit Katariya

  • Guido Preite Profile Picture
    Guido Preite 54,063 Moderator on at
    RE: Object reference not set to an instance of an object web service

    look, I checked the code you posted, I don't know if you pasted something different from the code you are running.

    this line 13              

    Entity ownerUser = service.Retrieve("systemuser", Guid.Parse("recordId"), new ColumnSet(true));

    doesn't work because Guid.Parse("recordId") gives an exception

  • Maryam_m Profile Picture
    Maryam_m 60 on at
    RE: Object reference not set to an instance of an object web service

    oh it seams you you got it wrong I give an ID to Guid.parse() method in format of string

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,063 Moderator on at
    RE: Object reference not set to an instance of an object web service

    line 13

    Entity ownerUser = service.Retrieve("systemuser", Guid.Parse("recordId"), new ColumnSet(true));

    you are parsing a string (that contains "recordId") and not a value, that line returns an error

  • Maryam_m Profile Picture
    Maryam_m 60 on at
    RE: Object reference not set to an instance of an object web service

    Thanks for your answer

    Well my web service is working properly. I have another method and is has no problem in addition I generate a file in my bad method and write in that file during working the method this is my code:

    public string GetReceivedFaxes(int receivedFaxId)

           {

               try

               {

    1                _logFile = string.Format(@"e:\log\_{0}.txt", Guid.NewGuid());

    2                var connectionString = @"AuthType = AD; Url = mycrmAddress/;Username=userName;Password=passWord";

    3                Log("test2");

    4                CrmServiceClient conn = new CrmServiceClient(connectionString);

    5                Log("test3");

    6                IOrganizationService service;

    7                Log("test4");

    8                service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? 9(IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;

    10                Log("test5");

    11                List<receivedFax> allReceivedFax = ReceiveFax(receivedFaxId);

    12                Log("test6");

    13                Entity ownerUser = service.Retrieve("systemuser", Guid.Parse("recordId"), new ColumnSet(true));

    14                EntityReference ownerReference = ownerUser.ToEntityReference();

    15                Log(ownerUser.Attributes["fullname"].ToString());

    16                for (int i = 0; i < allReceivedFax.Count; i++)

    17                {

    18                    Log("we are ok");

    19                    Guid recordId = CreateFax(Guid.Parse("recordId"), allReceivedFax[i], ownerReference, service);

    20                    Log("TEST");

    21                    Activate(service, recordId, 1, 4);

    22                    Log(recordId.ToString());

    23                    Entity recordCreated = service.Retrieve("fax", recordId, new ColumnSet(true));

    24                    EntityReference recordCreatedReference = recordCreated.ToEntityReference();

    25                    CreateNoteAttachment("ReceivedFaxMessage", "PDFFileForReceivedFax", allReceivedFax[i].FaxFileBase64, 26recordCreatedReference, service);

    27                }

    28                return "Fax created by this identifier: " + "\n" + receivedFaxId.ToString();

    29            }

    30            catch (Exception ex)

    31            {

    32                return "There is an error: "+ex.Message;

    33            }

    34

    35        }

    my problem is in line 13 and 19. I used service.create() method in createfax method and that creates an error.

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,063 Moderator on at
    RE: Object reference not set to an instance of an object web service

    that error message can refer to different situations, in what you described the most common one is that your webservice is not able to retrieve the connection string when it's deployed to IIS.

    First I will make sure if it can be read properly (like just getting the value and put as output of your webservice without connecting it), but without debugging you need to provide some output in a similar way to understand the root problem.

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans