如何在C#中使用SOAP API验证ServiceNow(SNOW)用户?

时间:2017-05-29 14:14:17

标签: c# asp.net web-services soap

我正在开发应用程序控制台,用于列出所有在SNOW中发生的事件。 我已经通过在IDE中添加服务引用并基于服务引用调用函数来实现了这一点......但是如何使用服务引用来验证SNOW用户有点混淆......

我的App.config文件

`<?xml version="1.0" encoding="utf-8" ?>
     <configuration>
       <startup>
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
       </startup>
   <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="ServiceNowSoap" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000" />
      <security mode="Transport">
        <transport clientCredentialType="Basic" proxyCredentialType="Basic" realm="">
          <extendedProtectionPolicy policyEnforcement="Never"/>
         </transport>
          <message clientCredentialType="UserName" algorithmSuite="Default"/>
        </security>
      </binding>
      <binding name="ServiceNowSoap1" />
    </basicHttpBinding>
  </bindings>
  <client>
       <endpoint address="https://****.service-now.com/incident.do?SOAP"
         binding="basicHttpBinding" bindingConfiguration="ServiceNowSoap"
       contract="ServiceReference1.ServiceNowSoap" name="ServiceNowSoap" />
   </client>
</system.serviceModel>
</configuration>

我的mainwindow.xaml

public MainWindow()
    {
        InitializeComponent();

        ServiceReference1.ServiceNowSoapClient soapClient = new ServiceReference1.ServiceNowSoapClient();
        soapClient.ClientCredentials.UserName.UserName = "****";
        soapClient.ClientCredentials.UserName.Password = "*****";

        ServiceReference1.getRecords Records = new ServiceReference1.getRecords();
        ServiceReference1.getRecordsResponseGetRecordsResult[] Results = soapClient.getRecords(Records);
        DataTable data = new DataTable();
        data.TableName = "ServiceNow Incidents";
        data.Columns.AddRange(new DataColumn[]{new DataColumn("Number"),  
                                                 new DataColumn("Opened"),
                                                 new DataColumn("Short Description"),
                                                 new DataColumn("Caller"),
                                                 new DataColumn("Priority"),
                                                 new DataColumn("State"),
                                                 new DataColumn("Category"),
                                                 new DataColumn("Assigned Group"),
                                                 new DataColumn("Assigned To"),
                                                 new DataColumn("Updated On"),
                                                 new DataColumn("Updated By")});

        for (int i = 0; i < Results.Length; i++)
        {
            DataRow row = data.NewRow();
            row["Number"] = Results[i].number;
            row["Opened"] = Results[i].opened_at;
            row["Short Description"] = Results[i].short_description;
            row["Caller"] = Results[i].caller_id;
            row["Priority"] = Results[i].priority;
            row["State"] = Results[i].state;
            row["Category"] = Results[i].category;
            row["Assigned Group"] = Results[i].assignment_group;
            row["Assigned To"] = Results[i].assigned_to;
            row["Updated On"] = Results[i].sys_updated_on;
            row["Updated By"] = Results[i].sys_updated_by;
            data.Rows.Add(row);
        } 

        gridview.DataContext = data.DefaultView;
        gridview.Items.Refresh();
    }

0 个答案:

没有答案