使用 .Net 调用 Service Now Web 服务

发布于 2024-12-07 13:32:14 字数 1843 浏览 2 评论 0原文

我正在尝试从 .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);
        }
    }
}

效果很好。以下是不适用于 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。我正在按照页面上的说明进行操作。

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

I am trying to call Service Now's webservice from .Net and I can make it work fine for inserting a record, but I can not get any GETs to work. Here is my working INSERT code:

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);
        }
    }
}

That works fine. Here is the code that does not work for 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;
    }
}

When I run that code, response is always null. I am following the instructions on this page.

I know that it is connecting because if I kill the credentials line I get an unauthorized error. Any ideas what I am doing wrong here? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零度° 2024-12-14 13:32:14

来自 C# Web 服务的 ServiceNow wiki:此处

如果您在您的网络服务中收到“空”响应
客户端代码,那么您可能错过了本教程中的步骤
将 elementFormDefault 设置为“False”...请记住
更改后根据 WSDL 重新编译代码
设置并保存。

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

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

From the ServiceNow wiki on C# Web Services: 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.

The property can be found within the ServiceNow instance at: System
Properties > Web Services. Set it to false, and you should no longer
receive null from the getRecords response.

Here's a screenshot of the property:
Screenshot of the image

一身软味 2024-12-14 13:32:14

如果您有兴趣,我已经编写了一组肥皂类来获取一些信息并将其投入服务。目前,我在工作中需要做的事情非常有限,但应该适用于任何人。

https://github.com/jeffpatton1971/mod-ServiceNOW

欢迎查看

If you're interested I've written a set of soap classes to get and put some information into servicenow. It's pretty limited at the moment to just what I need to be able to do at work, but should work for anyone.

https://github.com/jeffpatton1971/mod-ServiceNOW

Feel free to check it out

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文