c# - 使用 .Net 调用 Servicenow Web 服务

标签 c# .net web-services servicenow

我正在尝试从 .Net 调用 Service Now 的网络服务,我可以让它正常工作以插入记录,但我无法让任何 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);
        }
    }
}

这很好用。以下是不适用于 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;
    }
}

当我运行该代码时,response 始终为 null。我正在按照 this 上的说明进行操作页面。

我知道它正在连接,因为如果我关闭凭据行,我会收到未经授权的错误。知道我在这里做错了什么吗?谢谢!

最佳答案

来自 C# Web 服务上的 ServiceNow wiki:here

If you are receiving a "null" response from your web service in your client code, then you may have missed the step in this tutorial for setting the elementFormDefault setting to "False" ... Please remember to recompile your code against the WSDL after you have changed this setting and saved it.

该属性可以在 ServiceNow 实例中找到:System 属性 > Web 服务。将它设置为 false,你不应该再 从 getRecords 响应中接收 null。

这是该属性的屏幕截图: Screenshot of the image

关于c# - 使用 .Net 调用 Servicenow Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7611866/

相关文章:

c# - 为什么接口(interface)变量实例化是可能的?

java - 在 WEB API 服务器和 Android 客户端应用程序之间共享模型的最佳实践是什么

c# - 在 Web 服务中运行同步方法

c# - 重用 LINQ 查询

c# - Recommender.GetRecommendedSymbolsAtPositionAsync 返回太多符号

javascript - 我如何在没有 ajax 调用的情况下在 window.location 中传递数组

c# - 存储过程中的问题

.net - 获取变量(非硬编码)名称?

c# - 从 SOAP 消息(没有 WSDL)生成 Web 服务接口(interface)?

c# - 如何在列表框上实现增量搜索?