2

我正在尝试在 .Net/C# 中使用其中的一些服务。某些服务可以很容易地使用,但与其他服务相比,我遇到了误导性错误

这是代码的一部分:

        input.AcademicProgramOfStudySelectionByName = new AcademicProgramOfStudyByNameQueryMessage_syncAcademicProgramOfStudySelectionByName();
        input.AcademicProgramOfStudySelectionByName.AcademicProgramOfStudyName.languageCode = "DE";

我在第二行收到错误“对象引用未设置为对象实例”。但我已经在第一行创建了对象!

相同的代码适用于其他一些服务!

4

2 回答 2

0

您创建了对象 input.AcademicProgramOfStudySelectionByName,但没有创建它的成员input.AcademicProgramOfStudySelectionByName.AcademicProgramOfStudyName。看起来, class 的构造函数AcademicProgramOfStudyByNameQueryMessage_syncAcademicProgramOfStudySelectionByName并没有填充它的 member AcademicProgramOfStudyName。因此,当您尝试将值分配给 的成员AcademicProgramOfStudyName并且该实例为NULL时,您会遇到异常。

示例代码:

    AcademicProgramOfStudyByNameQueryResponse_InClient client = 
        new AcademicProgramOfStudyByNameQueryResponse_InClient(); 


    client.ClientCredentials.UserName.UserName = "XX";
    client.ClientCredentials.UserName.Password = "YY";

    AcademicProgramOfStudyByNameQueryMessage_sync input =
        new AcademicProgramOfStudyByNameQueryMessage_sync();


    input.AcademicProgramOfStudySelectionByName = new AcademicProgramOfStudyByNameQueryMessage_syncAcademicProgramOfStudySelectionByName();

    // this is the member that currently is still NULL and has to be created:
    input.AcademicProgramOfStudySelectionByName.AcademicProgramOfStudyName = new <insert whatever class is needed here>

    // now this should work without throwing an exception
   input.AcademicProgramOfStudySelectionByName.AcademicProgramOfStudyName.languageCode = "DE";

    AcademicProgramOfStudyByNameResponseMessage_sync output = 
        new AcademicProgramOfStudyByNameResponseMessage_sync(); 

    output = client.AcademicProgramOfStudyByNameQueryResponse_In(input);
于 2012-05-23T12:11:00.870 回答
0

这真的很奇怪。看到这个比较:在这段代码中我得到了错误

        AcademicProgramOfStudyByNameQueryResponse_InClient client = 
            new AcademicProgramOfStudyByNameQueryResponse_InClient(); 


        client.ClientCredentials.UserName.UserName = "XX";
        client.ClientCredentials.UserName.Password = "YY";

        AcademicProgramOfStudyByNameQueryMessage_sync input =
            new AcademicProgramOfStudyByNameQueryMessage_sync();


        input.AcademicProgramOfStudySelectionByName = new AcademicProgramOfStudyByNameQueryMessage_syncAcademicProgramOfStudySelectionByName();
        input.AcademicProgramOfStudySelectionByName.AcademicProgramOfStudyName.languageCode = "DE";

        AcademicProgramOfStudyByNameResponseMessage_sync output = 
            new AcademicProgramOfStudyByNameResponseMessage_sync(); 

        output = client.AcademicProgramOfStudyByNameQueryResponse_In(input);

在这段代码中我没有!

        CustomerSimpleByNameAndAddressQueryResponse_InClient client =
          new CustomerSimpleByNameAndAddressQueryResponse_InClient();

        client.ClientCredentials.UserName.UserName = "XX";
        client.ClientCredentials.UserName.Password = "YY";

        CustomerSimpleByNameAndAddressQueryMessage_sync input = new CustomerSimpleByNameAndAddressQueryMessage_sync();

        input.CustomerSimpleSelectionByNameAndAddress = new CustomerSimpleByNameAndAddressQueryMessage_syncCustomerSimpleSelectionByNameAndAddress();
        input.CustomerSimpleSelectionByNameAndAddress.CustomerAddressCityName = "Berlin";

        CustomerSimpleByNameAndAddressResponseMessage_sync output = new CustomerSimpleByNameAndAddressResponseMessage_sync();

        output = client.CustomerSimpleByNameAndAddressQueryResponse_In(input);
于 2012-05-24T09:09:20.973 回答