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

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

(0) ShareShare
ReportReport
Posted on by 62

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

I have the same question (0)
  • Maryam_m Profile Picture
    62 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
    10,409 Super User 2025 Season 2 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
    10,409 Super User 2025 Season 2 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
    54,084 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
    62 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
    54,084 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
    62 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
    54,084 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

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
Daniyal Khaleel Profile Picture

Daniyal Khaleel 122

#2
DAnny3211 Profile Picture

DAnny3211 101

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans