我正在尝试从 .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。
这是该属性的屏幕截图:
关于c# - 使用 .Net 调用 Servicenow Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7611866/