Error description: Net Development WebService invokes the Microsoft.SharePoint.dll server-side object model, there are applications that cannot find the Web site, or there are 500 errors.
Error screenshot:
[WebService call page ERROR]
System.IO.FileNotFoundException: Find a WEB application that is not in place in http://localhost. Verify that you typed the URL correctly. If the URL needs to provide existing content, the system administrator may need to add a new request URL mapping to the specified application. In Microsoft.SharePoint.SPSite. ctor (SPFarm Farm, Uri RequestUri, Boolean contextsite, Spusertoken usertoken) in Microsoft.SharePoint.SPSite. ctor (String requesturl) in WebApplication1.WebService1.GetWebID (string siteurl) location C:\Users\Administrator\Documents\ Visual Studio 2010\projects\webapplication1\webapplication1\webservice1.asmx.cs: line number 26
[Full error Tip]
[WebMethod(Description = "获取WebID")]
public string GetWebID(string SiteUrl)
{
SPSite site = null;
SPWeb web = null;
site = new SPSite(SiteUrl);
web = site.OpenWeb();
return "ID:" + web.ID.ToString();
}
[Test code, get WebID]
Initially thought it was an alternate access mapping, or a problem with modifying the host file, because the application was not found, then the URL was opened in the browser, it was found to be open, and the permissions were not sufficient, because it was net calling the SharePoint DLL and then the claim was not resolved.
Check for a long time, later found that the code preview has a problem, but after the release, call WebService but no problem, feel very strange, but there is no way to debug. Later looked at the data, found that said vs IIS 64-bit support, although it is not clear that it is not the problem here, but after the release, debugging this machine IIS, found that the problem does not exist (thanks to the Blogger's article, refer to the blog post address appended).
Workaround: Publish your own project to local IIS, and then attribute –web– use the local IIS Web server, fill in the format [url:port/site name], and then debug it.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/
After the change, the discovery of the call, there is the phenomenon of the yellow pages ["Denied access. (Abnormal from hresult:0x80070005 (e_accessdenied)) "], later, by a friend to remind, found that the wood has to mention the right, rookie is rookie, before debugging the dizzy, incredibly ignored the right to mention.
The right to raise code:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
代码段….
});
Then there is, someone said to write the console, will also appear to find the application of the situation, the resulting target platform into 64-bit, or tune to [any CPU], they have not encountered, but these webservice call Sharepoint.dll is not useful.