.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Sharepoint2010 Custom Webservice SPContext

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :C#

I wrote a custom webservice called Service.asmx in which I deployed its WSDL/DISCO aspx files and the webservice asmx into sharepoint's ISAPI folder and the webservice's strongly named dll into the GAC.  These work as they should.

If I create a webservice consumer that invokes a test method on my custom webservice, my webservice is able to obtain the SPContext of the sharepoint site pointed to by the URL.

If I open internet explorer on my webservice and manually invoke the same test method from the WSDL menu, my webservice reports the SPContext of the same sharepoint site is null.

In both cases the URL (for the reference to my webservice in the consumer, and what I keyed into internet explorer) is the same:


Why does the webservice sometimes lose its SPContext?  How do I get the SPContext when I call the webservice from internet explorer?  Shouldn't the two invocations of the webservice not behave the same?  What am I missing here?


View Complete Post

More Related Resource Links

Sharepoint2010 custom webservice and GAC


Is it absolutely neccessary to deploy custom created webservice dlls that run out of sharepoint 2010 in the GAC?  Is there any way to create a custom webservice that runs out of sharepoint without having to strong name the assemblies?

I need to develop a webservice that accesses sharepoint 2010 APIs to support a seperate CRM 3.0 application that needs to create folders in sharepoint 2010 and upload documents.  Because CRM 3.0 can only run in the .net 1.1 framework, I have to create a webservice in sharepoint for CRM to call that acts as a proxy and executes CRM requests against sharepoint 2010 on its behalf.


Problem passing custom object returned by the same webservice among two separate projects

I am running into casting issue with this scenario: 1. I made a custom object lets call it EmployeeObject.  2. The Employee object is wrapped in the EmployeeWebservice.  3. I have a client application project lets call it EmployeeClientApplication and a class library called DoSomeWorkClassLibrary.  Both EmployeeClientApplication and DoSomeWorkClassLibrary reference the EmployeeWebService and need to be able to pass the EmployeeObject back and forth.  4. The EmployeeClientApplication also references the DoSomeWorkClassLibrary. 5. The employeeObject in the EmployeeClientApplication becomes EmployeeClientApplication.EmployeeWebService.EmployeeObject. 6. The employeeObject in the DoSomeWorkClassLibrary becomes DoSomeWorkClassLibrary.EmployeeWebService.EmployeeObject. 7. The DoSomeWorkClassLibrary has a method called DoSomeWork that takes an EmployeeObject. When I try to pass employeeObject from EmployeeClientApplication to DoSomeWorkClassLibrary by doing something like this: DoSomeWorkClassLibrary.DoSomeWork(EmployeeClientApplication.EmployeeWebService.EmployeeObject), I am getting Unable to convert EmployeeClientApplication.EmployeeWebService.EmployeeObject to DoSomeWorkClassLibrary.EmployeeWebService.EmployeeObject.  I have searched high and low to fix this issue, I have tried changing the namespace of the reference.cs file of the webservice in

how to add custom site collection template in central admin site in SharePoint2010?

hi all, how can we add custom template in cendtral admin in sharepoint 2010? In 2007, we can add by using the stsadm tool addtemplate operation....but 2010 tremplate is saved as a solution file not a .stp file...so how we can add this template in central admin site in SharePoint 2010? Please give me some suggestions...... thanks in advance.....

Host custom webservice in sharepont

How to host a custom webservice in sharepoint?Manvir

Getting Exception: Testing Custom Webservice deployed on SharePoint 2010 using VS 2010 Pro


Hi there, I am a newbie in Webservice programming.
The exception:
The Address property on ChannelFactory.Endpoint was null.  The ChannelFactory's Endpoint must have a valid Address specified.
I have read many sites in internet (found unfortunately only for VS2008 and SP2007) and tried many things, but always failed. I really need your help to solve this problem. Thank you in advance.

I am trying to test a custom webservice deployed on Sharepoint 2010:

The webservice can be called: http://localhost/_vti_bin/StructureSearch/StructureSearchService.svc
And I got instructions like below: 

svcutil.exe http://localhost/_vti_bin/StructureSearch/StructureSearchService.svc?wsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:

C# .. and so on

So I created a simple c# console app like following:

SPContext.Current is null in a WebService in the 12 hive layouts



  I do not understand why I cannot get the SPContext.Current instance.  It must be an IIS Setting because I get it on one machine and not on another, using identical code.

SPContext.Current is null In Custom Membership ValidateUser


Hi,I just get a problem getting SPContext.Current in Custom membership Provider.

We have successfully plugin the custom membership into Sharepoint foundation 2010. We tried to programmically update the user's full name after user logs in and it failed in 2010 version. (good in 2007)

This is the simplified code. The class is a custom membership provider.Strangely, this only happens in 2010 version and never raised a problem in 2007.

public override bool ValidateUser(string username, string password)
   bool isvalid = false;

    if(username=="admin" && password="pwd")
      isvalid = true;
     var webContext = SPContext.Current.Web; //this returns null

   catch (System.Web.Services.Protocols.SoapException exp)
    Logger.WriteLog(exp.InnerException.ToString(), "wss login error");
   return isvalid;


Please Help. Thank you.



creating a custom namespce for a webservice



I am working on a web service right now and I am using the default namespace which is below one;

[WebService(Namespace = "http://tempuri.org/")]

How can I create a custom user interface?

Like this page;


search.asmx SharePoint2010 WebService


Hi All,

I am querying SharePoint 2010 from an external ASP.NET application using the WSS Search web service (/_vti_bin/search.asmx).

The page currently just has a text box and a submit button, with a standard gridview control. 

I want to use the queryex method which returns the results in a DataSet and I'm using the SQL-based search format with a specific scope.

Can anybody help me to code for the same ASAP.??



Custom Edit and New For a List in sharepoint2010


Hello can anyone please help me. I have a project which i created for WSS3.0 this is a  list definition and i changed new and edit forms for this list, how can i do the same in sharepoint Foundation 2010 usig visual studio 2010


Custom Edit and New For a List in sharepoint2010


Hello can anyone please help me. I have a project which i created for WSS3.0 this is a  list definition and i changed new and edit forms for this list, how can i do the same in sharepoint Foundation 2010 usig visual studio 2010


Thanks in advance

Custom Edit and New For a List in sharepoint2010


Hello can anyone please help me. I have a project which i created for WSS3.0 this is a  list definition and i changed new and edit forms for this list, how can i do the same in sharepoint Foundation 2010 usig visual studio 2010

Webservice versions.asmx: Getversions-method returns error on an item of a custom list.


I using GetVersions from the webservice http://server/_vti_bin/versions.asmx. This method works Okay in SharePoint 2007, and in SharePoint 2010 it also works Okay on documents from a document library. But when I used on an item from a custom list, it returns an error stating: "Value cannot be null.\r\nParameter name: key". In SharePoint 2007 I could retrieve the histroy on an item with the call GetVersions("Lists/MyCustomList/5_.000"), in SharePoint 2010 this fails.

Do I need to change the parameter, or use another filename for an item instead of "5_.000"? Does any one have the same experience?

Thank you

sharepoint 2010 custom webservice, visual studio 2010, unable to get reference - content type is tex


I followed the MSDN example in how to create a custom webservice that integrates with sharepoint at http://msdn.microsoft.com/en-us/library/ms464040.aspx

I'm able to successfully call the custom webservice it walks you through from internet explorer out of a sharepoint 2010 site using a URL such as http://vm-spproduction/sites/resource/_vti_bin/service.asmx

And, I'm able to successfully call the same custom webservice from internet explorer out of the same sharepoint 2010 server with the URL http://vm-spproduction/_vti_bin/service.asmx

In Visual Studio 2010 (running on the same hardware server as sharepoint 2010), I am able to bring up the same custom webservice in the add web reference using the advanced buttons of the add service reference dialog.  But, when the custom webservice is found, visual studio reports the following error:

The document at the url http://vm-spproduction/sites/resource/_vti_bin/service.asmx was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from '

Deploy custom webservice to web application



I'm writing custom webservices for SharePoint 2010. Now generally it involves deploying .svc files to the ISAPI directory, which makes them available in http://server/_layouts/_vti_bin.

Works great, but this deploys the webservice to all web applications at once. In a shared environment this isn't preferable. So how can I deploy the webservice to a single webapp? I guess that means the .svc should be somewhere in the database instead of the filesystem. Is this doable and a good solution? Or are there other ways to acheive the same.

I'd like to have a solution which deploys to the web application scope. Updon deployment, I can select the web application(s) to deploy it to which makes the webservice avaiable in those and only those web apps.

MCTS Web Application Development, SharePoint enthousiast.

Manually configure (custom) binding for Java-based webservice



this is a follow up to my question Error "An unsupported security policy assertion was detected" when processing a WSDL with Svcutil.exe.

It seems that I'll get no further feedback on this, so I'll go with the assumption that it's not possible to use Svcutil.exe to generate functional client code from the WSDLs of the there mentioned services.

The main problem seems to be the security policies which are completely ignored, so no meanigful binding gets generated.

Therefore I guess I've to manually set up a (custom) binding to produce requests the conform to what the services expecting.
Here's an example for a service requests, it uses an SCT (issued by the corresponding STS) for authentication:

<?xml version="1.0" encoding="UTF-8"

Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend