使用.Net调用Service Web Webservice

Vyd*_*ope 3 .net c# web-services servicenow

我试图从.Net调用Service Now的web服务,我可以使它在插入记录时工作正常,但我无法使用任何GET工作.这是我的工作INSERT代码:

public void insertTable(string tableName, string schema, string columnInfo, string shortDesrcipt, string longDescript)
{
    using (ServiceNow_u_database_table tableReference = new ServiceNow_u_database_table())
    {
        insertResponse response = new insertResponse();

        System.Net.ICredentials cred = new System.Net.NetworkCredential(Properties.Settings.Default.UserName, Properties.Settings.Default.Password);
        tableReference.Credentials = cred;

        insert tableInsert = this.getTableData(tableName, schema, columnInfo, shortDesrcipt, longDescript);
        try
        {
            response = tableReference.insert(tableInsert);
        }
        catch (Exception error)
        {
            Console.WriteLine(error.Message);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这很好.以下代码不适用于GET:

using (ServiceNow_u_database_table tableReference = new ServiceNow_u_database_table())
{
    ServiceNowExport.com.servicenow.libertydev.u_database_table.getRecords recordGet = new getRecords();
    System.Net.ICredentials cred = new System.Net.NetworkCredential(Properties.Settings.Default.UserName, Properties.Settings.Default.Password);
    tableReference.Credentials = cred;

    recordGet.name = this._tablePrefix + tableName;
    getRecordsResponseGetRecordsResult[] response = tableReference.getRecords(recordGet);
    if (response != null && response.Count() > 0)
    {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行该代码时,response总是如此null.我下面就说明这个页面.

我知道它正在连接,因为如果我杀了凭证行,我会收到未经授权的错误.我在这里做错了什么想法?谢谢!

Joe*_*oey 8

来自C#Web Services上的ServiceNow wiki:在这里

如果您在客户端代码中从Web服务收到"null"响应,那么您可能错过了本教程中将elementFormDefault设置为"False"的步骤...请记住在以后针对WSDL重新编译代码您已更改此设置并保存.

该属性可以在ServiceNow实例中找到:系统属性> Web服务.将其设置为false,您不应再从getRecords响应中收到null.

这是该属性的屏幕截图: 图像的屏幕截图