我很難實現Web服務客戶端。我正在使用Web引用查詢SharePoint 2010 Web服務。下面的代碼在try塊內的行上引發異常。Web服務拋出異常
SoapService.Lists service = new SoapService.Lists();
service.Credentials = CredentialCache.DefaultCredentials;
XmlDocument doc = new XmlDocument();
XmlNode query = doc.CreateNode(XmlNodeType.Element,"Query","");
XmlNode viewFields = doc.CreateNode(XmlNodeType.Element,"ViewFields","");
XmlNode queryOptions = doc.CreateNode(XmlNodeType.Element,"QueryOptions","");
query.InnerXml = @"<Where><IsNotNull><FieldRef Name='Vendor Name'/></IsNotNull></Where>";
viewFields.InnerXml = @"<FieldRef Name='Vendor Name'/>";
queryOptions.InnerXml = @"<QueryOptions/>";
try
{
XmlNode response = service.GetListItems("DLA-Suppliers", null, query, viewFields, null, queryOptions, null); // exception thrown
}
catch (System.Web.Services.Protocols.SoapException e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.Detail);
Console.WriteLine(e.StackTrace);
}
這裏是例外(SoapServerException)堆棧跟蹤:
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at DLAUpdateSP.SoapService.Lists.GetListItems(String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions, String webID) in c:\users\user\documents\visual studio 2010\Projects\DLAUpdateSP\Web References\SoapService\Reference.cs:line 455
at DLAUpdateSP.Program.UpdateSuppliers(String fileLocation) in C:\Users\user\Documents\Visual Studio 2010\Projects\DLAUpdateSP\Program.cs:line 58
有沒有人有任何想法?除了堆棧跟蹤之外,異常的屬性幾乎全部爲空。我從來沒有做過SOAP,所以這對我來說真的很新鮮。任何幫助真的很感激。
我沒有創建Web服務,這是SharePoint Web服務API的一部分。我不相信傳入空值是一個問題,因爲它是在MSDN文檔中完成的:http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12) .aspx – Nathan
啊,我看到了...我很驚訝MS建議手動操縱XML字符串來訪問一個服務......它太不雅觀了。也就是說,我不知道你的代碼發生了什麼......我唯一的其他建議是,如果可以的話,可能檢查SharePoint服務器上的日誌。 – derekmckinnon
不幸的是我沒有直接訪問SharePoint服務器。如果我這樣做,我不會使用Web服務。謝謝您的幫助。 – Nathan