2011-09-30 59 views
3

我想從.Net中調用Service Now的webservice,我可以使它適用於插入記錄,但我無法獲得任何GET s的工作。這是我的工作INSERT代碼:現在調用服務與.Net的Webservice

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頁面上的說明操作。

我知道它正在連接,因爲如果我殺了證書行,我會得到未經授權的錯誤。任何想法我在這裏做錯了嗎?謝謝!

+1

你給出了'GET'似乎是不完整的片段。這裏給出的是返回'true'而不是'response'。這可能是原因嗎? –

+0

不,在回到真實之前,在if中檢查迴應。該響應應該有它在其中找到的表格(我知道表格在那裏,因爲我爲此測試創建了它)。返回true返回它發現表,但由於我沒有得到響應,所以現在沒有被使用。 – VydorScope

回答

0

如果你有興趣,我寫了一組皁類來獲得,並把一些信息到的ServiceNow。目前我在工作中需要做的事情非常有限,但應該爲任何人工作。

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

隨時檢查出來

+0

謝謝 - 但是現在這個問題已經三年了,我已經忘記了。實際上我從頭開始構建我自己的SOAP接口和類,並完全忽略了他們的WSDL。這是實現它的唯一方法。我有完整的CRUD工作,但我不再在該公司工作,並將代碼留下。據我所知,他們今天仍在使用該代碼。 – VydorScope

7

從C#的Web服務的ServiceNow維基:here

如果您收到來自您的Web服務的「空」響應您的 客戶端代碼,那麼你可能已經錯過了本教程步驟 將elementFormDefault設置設置爲「False」...在您更改此 設置並保存後,請記住 重新編譯您的代碼與WSDL。

該屬性可以在ServiceNow實例中找到:系統 屬性> Web服務。將其設置爲false,並且不應再從收到getRecords響應中的空值。

這裏的屬性截圖: Screenshot of the image

+0

這應該被接受爲答案!非常有幫助 – makim

+0

+1非常棒,我希望我在3小時前看過這個:/ – Icarus

+0

我在發佈問題之前已經嘗試了這個答案,但它對我沒有幫助。 我實際上從頭開始構建我自己的SOAP接口和類,並完全忽略了他們的WSDL。這是實現它的唯一方法。我有完整的CRUD工作,但我不再在該公司工作,並將代碼留下。據我所知,他們今天仍在使用該代碼。 – VydorScope