使用 .Net 调用 Service Now Web 服务
我正在尝试从 .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 GET
s 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 C# Web 服务的 ServiceNow wiki:此处
该属性可以在 ServiceNow 实例中找到:系统
属性>网络服务。将其设置为 false,您不应该再
从 getRecords 响应中接收 null。
这是该属性的屏幕截图:

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

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