Sharepoint 2010 Custom WebService cannot find a site application problem

Source: Internet
Author: User
Tags iis object model visual studio visual studio 2010

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.