我有一个使用WCF端点调用SharePoint 2007 Lists.asmx服务的Web应用程序。为了确定为什么在调用GetListItems方法时收到500响应,我发现它在U2U Caml查询生成器中执行查询后开始成功。也就是说,执行U2U查询后,Web应用程序将停止获取500响应,并可以使用其WCF服务引用成功检索列表项,直到执行iisreset。使用ASMX Web参考调用后,只能使用WCF客户端调用SharePoint 2007 Web服务
作为对此发现的回应,我创建了一个控制台应用程序,通过WCF服务参考对GetListItems进行简单调用。我已经缩小到的是来自WCF服务引用的调用仅在从传统的.net 2.0 Web引用代理进行调用后才起作用。下面是我的控制台应用程序示例代码(这是我一直在VS Web服务器上运行):
string listName = "Reusable Content";
string viewName = String.Empty;
string rowLimit = null;
//Always Works
XmlDocument doc = new XmlDocument();
ListsAsmx.Lists oldSvc = new ListsAsmx.Lists();
oldSvc.Credentials = new System.Net.NetworkCredential("user1", "passwrod", "mydomain");
XmlNode result = oldSvc.GetListItems(listName, viewName, doc.CreateElement("Query"), doc.CreateElement("ViewFields"), rowLimit, doc.CreateElement("QueryOptions"), null);
//Only works after the above succeeds
string query = "<Query></Query>";
string viewFields = "<ViewFields></ViewFields>";
string queryOptions = "<QueryOptions></QueryOptions>";
ListsService.ListsSoapClient svc = new ListsService.ListsSoapClient();
svc.ClientCredentials.Windows.ClientCredential.UserName = "user1";
svc.ClientCredentials.Windows.ClientCredential.Domain = "passwrod";
svc.ClientCredentials.Windows.ClientCredential.Password = "mydomain";
svc.GetListItems(listName, viewName, XElement.Parse(query), XElement.Parse(viewFields), rowLimit, XElement.Parse(queryOptions), null);
所以,如果我注释掉sv2.GetListItems(...),做一个IISRESET,我得到的来自svc.GetListItems(...)的500响应。有趣的是,Web引用调用的起源并不重要。当我使用U2U Caml查询生成器发现它时,U2U始发于我的本地开发机器,并且WCF客户端调用始于Web服务器。即使我没有明确地设置svc的凭据(大概是因为它自动使用我的用户凭证),上面的代码也会成功。以下是ListsSoapClient的配置。你能帮我理解这里发生了什么,以及如何让svc自己成功?
<binding name="ListsSoap2" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="500000" maxBufferPoolSize="524288" maxReceivedMessageSize="500000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="5120000" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://devpladmin.mydomain.com/_vti_bin/Lists.asmx"
binding="basicHttpBinding" bindingConfiguration="ListsSoap2"
contract="ListsService.ListsSoap" name="ListsSoap" />
</client>
编辑
附加信息:
这是记录在事件查看器时,我收到了500:
Exception information:
Exception type: FileLoadException
Exception message: Could not load file or assembly 'Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)
Request information:
Request URL: https://devpladmin.mydomain.com:443/_vti_bin/Lists.asmx
Request path: /_vti_bin/Lists.asmx
Thread information:
Thread ID: 10
Thread account name: MYDOMAIN\user1
Is impersonating: False
Stack trace: at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.SharePoint.CoreResource..cctor()
据我所知,SharePoint从不支持WSE。如果您的WSE代理工作正常,那将归因于它不使用WSE的任何功能,并且仅使用基本的ASMX功能。 –
而且,BTW,WSE不是“传统”,它已经过时。尤其是WSE 2.0,它比过时的WSE 3.0更为陈旧。我没有理由甚至在SharePoint的背景下思考WSE。 –
好的,也许我不知道我在说什么。我刚刚在.NET中开始使用WSE,并且可能误解了它包含的内容。当我说上面的WSE时,我的意思是VS 2010称为.NET 2.0 Web Reference(而不是服务引用)。请帮助我纠正我的语言,然后我会更新我的问题。对困惑感到抱歉。 – xr280xr