Ask a questionAsk a question
 

AnswerHow to access the list from web services.

  • Wednesday, November 04, 2009 5:37 AMwoodson.gen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
        I have web services to get the data from sharepoint list.it's working fine in deployement mode.When it's in developement i got the error.The same coding is working fine in Window application.When i debugge the  Web method i am getting error like below.

    {System.IO.FileNotFoundException: The Web application at http://ServerName:portnumber//sites//Sitecolectionname// could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
       at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
       at Microsoft.SharePoint.SPSite..ctor(String requestUrl)


    Any idea? Advance thanks for your help.

    Thanks
    WoodSon

Answers

  • Wednesday, November 04, 2009 8:24 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I really can't stop thinking that this is a dangerous way of working, even if you installed the web service on the same server as SharePoint runs, and even if you use it from that same machine.

    There are 2 different ways of working:
    - Or you develop your own independent web service and you call the SharePoint web services from it.
    - Or you develop a custom SharePoint web service and deploy it in the ISAPI folder of SharePoint, allowing you to use the SharePoint object model. I would choose for this last option. If you don't know how to develop and deploy web services in the SharePoint context, you can use this walkthrough (http://msdn.microsoft.com/en-us/library/ms464040.aspx). It seems difficult but if you follow the steps precisely as described, it is piece of cake.

    Hope this helps


    Karine Bosch

All Replies

  • Wednesday, November 04, 2009 5:45 AMAbdul Khalid Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    Can you pls share the pice of code?
    Also, what do you mean by Deployment mode and development mode? Where is the webservice hosted?
    Hope that helps, Abdul Khalid.
  • Wednesday, November 04, 2009 5:50 AMwoodson.gen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
     SPSite oSite = new SPSite("http://ServerName:portNumber//sites//SiteCollectionName//");  
                SPWeb oWeb = oSite.RootWeb;
                SPList _SPList = oWeb.Lists["ListName"];
    DataTable dt = _SPList.Items.GetDataTable();
    
    thanks for your reply.Above code only i used.Deployement mode means publish the web service into server.I am using the same for development purpose..
  • Wednesday, November 04, 2009 6:57 AMAbdul Khalid Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    If you run this code from a "Non Sharepoint" server, it will give error. Is this code running from sharepoint server or another machine?
    Also, i noticed the url format is wrong. try this way:
    SPSite oSite = new SPSite(@"http://ServerName:portNumber/sites/SiteCollectionName/");

    Note: If you just want to retrieve data from a sharepoint list/library, you can use the default sharepoint Lists.asmx webservice present at: [siteurl]/_vti_bin/Lists.asmx



    Hope that helps, Abdul Khalid.
  • Wednesday, November 04, 2009 7:44 AMwoodson.gen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    thanks for your reply.i am using sharepoint installed machine only.In that machine we have deployed our custome web service also.I am using the Custom web service Abdul.i gave "SPSite oSite = new SPSite(@"http://ServerName:portNumber/sites/SiteCollectionName/");" this url also getting the same issue.

  • Wednesday, November 04, 2009 8:24 AMKarine BoschMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I really can't stop thinking that this is a dangerous way of working, even if you installed the web service on the same server as SharePoint runs, and even if you use it from that same machine.

    There are 2 different ways of working:
    - Or you develop your own independent web service and you call the SharePoint web services from it.
    - Or you develop a custom SharePoint web service and deploy it in the ISAPI folder of SharePoint, allowing you to use the SharePoint object model. I would choose for this last option. If you don't know how to develop and deploy web services in the SharePoint context, you can use this walkthrough (http://msdn.microsoft.com/en-us/library/ms464040.aspx). It seems difficult but if you follow the steps precisely as described, it is piece of cake.

    Hope this helps


    Karine Bosch