Custom web service in SharePoint 2010
Hi,
I have developed one custom web service and deployed in inside 14 hive Layout folder. I have to consume this custom web service in WCF REST services. This WCF REST service will be consumed in to HTML 5 and javascript application (Presentation Layer). Here
is the code for Custom web service :
[WebMethod]
public string[] GetSponsorList()
string url = "https://ptmdev.bpiper.com/";
//string strUserName = "ravikant";
string sponsorTitle = string.Empty;
string[] arrTitle;
string[] myArray;
DataTable dtSponsor = new DataTable();
string error = string.Empty;
ArrayList myArrayList = new ArrayList();
try
dtSponsor.Columns.Add(new DataColumn("sValue", typeof(string)));
dtSponsor.Columns.Add(new DataColumn("sText", typeof(string)));
using (SPSite site = new SPSite(url))
using (SPWeb web = site.OpenWeb())
//SPUserToken userToken = web.AllUsers[strUserName].UserToken;
SPWebApplication webApplication = SPContext.GetContext(web).Site.WebApplication;
SPSiteCollection siteCollections = webApplication.Sites;
int i = 0;
if(web.CurrentUser!=null)
myArrayList.Add("User:"+web.CurrentUser.LoginName);
else
myArrayList.Add("Null User..");
foreach (SPSite siteCollection in siteCollections)
if (siteCollection.RootWeb.DoesUserHavePermissions(SPBasePermissions.ViewPages))
if (siteCollection.Url.ToString().ToLower().Contains("/sponsor/"))
sponsorTitle = siteCollection.RootWeb.Title;
if (string.IsNullOrEmpty(sponsorTitle))
arrTitle = siteCollection.Url.Split('/');
sponsorTitle = arrTitle[arrTitle.Length - 1];
dtSponsor.Rows.Add(new object[] { siteCollection.Url, sponsorTitle });
i = i + 1;
siteCollection.Close();
catch (Exception ex)
error = ex.Message;
myArrayList.Add(error);
if (dtSponsor.Rows.Count == 0)
myArrayList.Add("No Data available 101");
myArrayList.Add("No Data available 102");
myArrayList.Add("No Data available 103");
for (int i = 0; i <= dtSponsor.Rows.Count - 1; i++)
for (int j = 0; j <= dtSponsor.Columns.Count - 1; j++)
myArrayList.Add(dtSponsor.Rows[i][j].ToString());
myArray = (string[])myArrayList.ToArray(typeof(string));
return myArray;
Above code will return a string array of SiteCollection URLs and Title. Th issue is siteCollection.RootWeb.DoesUserHavePermissions(SPBasePermissions.ViewPages)
logic is failed and due to this string array does not return desired result.
web object is not containing users information due to that DoesUserHavePermissions logic is
failing.
Urgent help is needed.
Thanks,
Ravi
Hi,
According to your post, my understanding is that you have issue about siteCollection.RootWeb.DoesUserHavePermissions(SPBasePermissions.ViewPages) logic when you custom web service.
You can use siteCollection.RootWeb.DoesUserHavePermissions( SPContext.Current.Web.CurrentUser, SPBasePermissions.ViewPages)
to check whether it works.
In addition, you can use a RunWithElevatedPrivileges delegate.
For more information, you can refer to:
“Attempted to perform an unauthorized operation” and SPWeb.DoesUseHavePermissions
Thanks,
Linda Li
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Linda Li
TechNet Community Support
Similar Messages
-
Calling an external web service from SharePoint 2010
Hi Friends,
Idea is to call an external web service from SharePoint 2010 list.
Can we do this using visual studio 2010, how.
another pointers, please advise.Hi,
You can create Windows Communication Foundation (WCF) web services that you can consume as external content types from Microsoft Business Connectivity Services (BCS).
For more information, you can refer to:
http://msdn.microsoft.com/en-us/library/office/gg318615(v=office.14).aspx
http://www.c-sharpcorner.com/UploadFile/Roji.Joy/connecting-to-a-web-service-using-business-connectivity-serv/
http://blogs.msmvps.com/windsor/2011/11/04/walkthrough-creating-a-custom-asp-net-asmx-web-service-in-sharepoint-2010/
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Refer classes of Microsoft.Office.Policy dll in Custom web service sharepoint
Hi ,
I have created a custom web service which refers to Microsoft.Sharepoint dll and Microsoft.Office.Policy dll.
Added reference tags to these two assemblies in disco file
deployed this web service to _vti_bin.
An error occurred during the compilation of the requested file, or one of its dependencies. The type or namespace name 'RecordsManagement' does not exist in the namespace
'Microsoft.Office' (are you missing an assembly reference?)
This dll is already in present in GAC not sure where else should we be copying this dll to?
Regards,
Harika
harika kakkireniHi,
Please try to remove the reference of the Microsoft.Office.Policy.dll then add reference it again and rebuild you project.
Also try to enable “In-Place Records Management” site collection feature.
More information:
http://techtrainingnotes.blogspot.com/2010/01/sharepoint-2010-assemblies-and.html
http://msmvps.com/blogs/windsor/archive/2011/11/04/walkthrough-creating-a-custom-asp-net-asmx-web-service-in-sharepoint-2010.aspx
Best Regards
Dennis Guo
TechNet Community Support -
SharePoint Apps and custom web services as remote services
Hello,
After reading documentation about Apps for SharePoint compared with SharePoint solutions I did not find any information about "You
can develop your custom web services as remote services.".
Could you please give me links or advise, where I can get information - "How to develop custom web services as remote services" using SharePoint 2013 Apps?Hi,
I would suggest you to use WCF service instead of Web Service,
also, SharePoint 2013 introduces a Representational State Transfer (REST) service that is comparable to the existing SharePoint client object models.
Get started with the SharePoint 2013 REST service
About develop custom web services as remote services,see Demo here:
SharePoint 2013: Custom REST service provides data to an app for SharePoint
Best Regards
Guangchao chen
TechNet Community Support -
Display Custom Fields in a SharePoint 2010 Content Query Web Part?
Using SharePoint 2010, Having Custom List With 4 Columns, Now I am Using Content Query Web-part To Display List Data ,But Currently It Display Only First Column, SO How to Display Custom Fields in a SharePoint 2010 Content By Query Web Part
AKshay NangareHi,
By default CQWP shows only one column. However, if you want to show more than one column, then CQWP needs to be customized. The property which you are looking for is CommonViewFields. It is used to specify the additional fields that you want to display in
the Web Part. See this for more information:
https://msdn.microsoft.com/en-us/library/ms497457%28v=office.14%29.aspx?f=255&MSPPError=-2147217396
Blog | SharePoint Learnings CodePlex Tools |
Export Version History To Excel |
Autocomplete Lookup Field -
Custom Login Web Part In SharePoint 2010 Forms Based
Hi ,
Im trying to make Custom Login Web Part In SharePoint 2010 Forms Based , all membership configration is done .
my question is why (Login1.username , Login1.password ) give this error :
login1 does not exist in the current context
protected
void
Login1_Authenticate(object
sender, AuthenticateEventArgs e)
02 {
03 string
membership = "MembershipProvider";
04 string
role = "RoleProvider";
05
06 e.Authenticated
= SPClaimsUtility.AuthenticateFormsUser(new
Uri(SPContext.Current.Web.Url),Login1.UserName,Login1.Password);
07
08 if
(!e.Authenticated) return;
09
10 SecurityToken
token = SPSecurityContext.SecurityTokenForFormsAuthentication(new
Uri(SPContext.Current.Web.Url), membership, role,
Login1.UserName,
Login1.Password);Error 1 No overload for method 'SecurityTokenForFormsAuthentication' takes 3 arguments
Error 2 The name Wss doesnot exisit in current context
Can anyone give sugeestion please
cant recitfy this error
protected void Login1_Authenticate(object sender,
AuthenticateEventArgs e)
02 {
03 string membership
= "MembershipProvider";
04 string role
= "RoleProvider";
05
06 e.Authenticated
= SPClaimsUtility.AuthenticateFormsUser(newUri(SPContext.Current.Web.Url),Login1.UserName,Login1.Password);
07
08 if (!e.Authenticated) return;
09
10 SecurityToken
token = SPSecurityContext.SecurityTokenForFormsAuthentication(newUri(SPContext.Current.Web.Url),
membership, role,
Login1.UserName,
Login1.Password); -
Hi,
I found a thread in this forum With an answere to a similiar question here:
http://social.technet.microsoft.com/Forums/en-US/28bc1e27-4a65-4c61-9b3e-cb9dad17f779/office-web-apps-preview-sharepoint-2010-documents-in-sharepoint-2013-search-results?forum=sharepointsearch&prof=required
...With the answere:
"OWA uses an access token to talk to SharePoint 2013. It cannot use this when talking to 2010. In order to work with 2010, you have to create a custom display template that converts the file url to an openurl link. "
BUT...
may anyone give more information how to do this?
Links to articles? Links to description and samples?
jikHi,
According to your description, my understanding is that you want to preview documents from SharePoint 2010 in search results in SharePoint 2013.
Per my knowledge, the Office Web Apps is configured to work with SharePoint 2013, so it will not work with documents in SharePoint 2010.
I recommend to configure Office Web Apps to work with SharePoint 2010
and make sure that documents can be previewed in SharePoint 2010 using Office Web Apps to see if the documents can be previewed in SharePoint 2013 search result.
http://technet.microsoft.com/en-us/library/ff431687(v=office.14).aspx
Best regards.
Thanks
Victoria Xia
TechNet Community Support -
How to call COPY web service from sharepoint in SAP
Hello Experts,
I want to call COPY web service from SharePoint in SAP web dynpro / JAVA application.
However, when I try to connect to web service and download wsdl using http:// <hostname:port>/_vti_bin/copy.asmx?wsdl
it results in Unauthorized error and doesnt complete the setup. Detail error is :
Error occurred while downloading WSIL file. Error message: Deserializing xml stream http:// <hostname:port>/_vti_bin/copy.asmx?wsdl
failed.com.sap.engine.services.webservices.espbase.wsdl.exceptions.WSDLException: Invalid Response Code: (401) Unauthorized. The requested URL was:"Connect to
http:// <hostname:port>/_vti_bin/copy.asmx?wsdl , used user to connect: userid"
I am trying to connect with server user account. Any idea on what authorizations might be required or any help on the scenario .
-AbhijeetHere's an example on how to delete a list item, hopefully this helps
package com.jw.sharepoint.examples;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.microsoft.sharepoint.webservices.CopySoap;
import com.microsoft.sharepoint.webservices.GetListItems;
import com.microsoft.sharepoint.webservices.GetListItemsResponse;
import com.microsoft.sharepoint.webservices.ListsSoap;
import com.microsoft.sharepoint.webservices.UpdateListItems.Updates;
import com.microsoft.sharepoint.webservices.UpdateListItemsResponse.UpdateListItemsResult;
public class SharePointDeleteListItemExample extends SharePointBaseExample {
private String delete = null;
private String deleteListItemQuery = null;
private String queryOptions = null;
private static final Log logger = LogFactory.getLog(SharePointUploadDocumentExample.class);
private static Properties properties = new Properties();
public Properties getProperties() {
return properties;
* @param args
public static void main(String[] args) {
logger.debug("main...");
SharePointDeleteListItemExample example = new SharePointDeleteListItemExample();
try {
example.initialize();
CopySoap cp = example.getCopySoap();
example.uploadDocument(cp, properties.getProperty("copy.sourceFile"));
ListsSoap ls = example.getListsSoap();
example.executeQueryAndDelete(ls);
} catch (Exception ex) {
logger.error("Error caught in main: ", ex);
public void executeQueryAndDelete(ListsSoap ls) throws Exception {
Date today = Calendar.getInstance().getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = simpleDateFormat.format(today);
String queryFormatted = String.format(deleteListItemQuery,formattedDate);
GetListItems.QueryOptions msQueryOptions = new GetListItems.QueryOptions();
GetListItems.Query msQuery = new GetListItems.Query();
msQuery.getContent().add(createSharePointCAMLNode(queryFormatted));
msQueryOptions.getContent().add(createSharePointCAMLNode(this.queryOptions));
GetListItemsResponse.GetListItemsResult result = ls.getListItems(
properties.getProperty("folder"), "", msQuery, null, "",
msQueryOptions, "");
writeResult(result.getContent().get(0), System.out);
Element element = (Element) result.getContent().get(0);
NodeList nl = element.getElementsByTagName("z:row");
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
String id = node.getAttributes().getNamedItem("ows_ID").getNodeValue();
String fileRefRelativePath = node.getAttributes().getNamedItem("ows_FileRef").getNodeValue();
logger.debug("id: " + id);
logger.debug("fileRefRelativePath: " + fileRefRelativePath);
String fileRef = properties.getProperty("delete.FileRef.base") + fileRefRelativePath.split("#")[1];
logger.debug("fileRef: " + fileRef);
deleteListItem(ls, properties.getProperty("folder"), id, fileRef);
public void deleteListItem(ListsSoap ls, String listName, String listId, String fileRef) throws Exception {
String deleteFormatted = String.format(delete, listId, fileRef);
Updates u = new Updates();
u.getContent().add(createSharePointCAMLNode(deleteFormatted));
UpdateListItemsResult ret = ls.updateListItems(listName, u);
writeResult(ret.getContent().get(0), System.out);
public void initialize() throws Exception {
logger.info("initialize()...");
properties.load(getClass().getResourceAsStream("/SharePointDeleteListItemExample.properties"));
super.initialize();
this.delete = new String(readAll(new File(this.getClass().getResource("/Delete.xml").toURI())));
this.deleteListItemQuery = new String(readAll(new File(this.getClass().getResource("/DeleteListItemQuery.xml").toURI())));
this.queryOptions = new String(readAll(new File(this.getClass().getResource("/QueryOptions.xml").toURI())));
Brandon James SharePoint Developer/Administrator -
401 Unauthorized Error When calling a SharePoint REST web service from SharePoint 2013 Workflow
We have our Workflow Manger installed on the same server as our SharePoint 2013 WFE development environment. When creating a SharePoint 2013 Workflow all Calls to a SharePoint 2013 REST web service results in a 401 Unauthorized error.
As an example I created a simple workflow that should return a JSON result. The REST Url returns the results in the browser without error.
Set Variable:webServiceUrl to https://<hostnamedsitecollection>/_vti_bin/client.svc/web/lists/getbytitle('ISR%20Approvers')/Items?$select=Title&$filter=Title%20eq%20%27General%27
then Build{...} Dictionary (Output to Variable:requestHeaders)
then Call [%Variable:webServiceUrl%] HTTP web service with request (ResponseContent to Variable:responseContent |ResponseHeaders to responseHeaders | ResponseStatusCode to Variable:responseCode)
The RequestHeader is set to the requestHeaders variable though the web service call properties
then Log Variable:responseCode to the workflow history list
After manually running the workflow in SharePoint on a list item in the ISR Approvers list it Logs "Unauthorized" in the Workflow History Log. It does this with every SharePoint REST web service call that I have tried through the workflow.
It doesn't have anything to do with the Workflow Manger being installed on the same machine as the SharePoint WFE does it?
Thank You for any insightHi,
According to your post, my understanding is that you had 401 Unauthorized Error when calling a SharePoint REST web service from SharePoint 2013 Workflow.
Please make sure you use the ‘Call HTTP Web Service’ correctly.
You can enter the URL into the brower to check whether it is correctly.
You need to
create the Request header requestHeaders
using a Dictionary:
Accept : application/json;odata=verbose
Content-Type : application/json;odata=verbose
To associate the
requestHeaders variable, select the Call action
property, set the RequestHeaders property to
requestHeaders.
Please refer to the following articles:
Working with Web Services in SharePoint 2013 Workflows using SharePoint Designer 2013
Calling the SharePoint 2013 Rest API from a SharePoint Designer
Workflow
In addtion, you need to make sure you install the workflow manager correctly.
More information:
Install and configure workflow for SharePoint Server 2013
Known Issues in Workflow Manager 1.0
Troubleshooting Workflow Manager 1.0 Management and Execution
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Standard Web Service and Customized Web Services with or without PI?
Hi All,
I want to know how I can use Standard Web Service available in SAP and customized Web Services
without PI Interface?
And what is the best practice to expose services ,via PI Interface or directly?
Thanks in advance!!
PushkarThis is purely based on your requirement. If you use PI middleware to expose web services, you get standard functionalities such as certificate authentication, logging, message reprocessing for the failed messages etc. If your requirement is so simple, then you might not need PI. In this case you can develop simple webdynpro for abap program to create webservice and expose the webservice in ECC webservice runtime. You can let anyone to consume within your network. other ways like exposing BAPI/RFC as webservice. I would recommend going with PI.
-
Way to use Visual Web part in sharepoint 2010 without using/installing third party tools
I want to know the way to use Visual Web part in sharepoint 2010 without using/installing third party tools.
Please provide me a link where i can actually know how it is done.+ to _eNo_,
Visual Studio 2010 has support for visual webpart, you can find that under Visual C# node in the Installed Templates section (if your preferred language is C#)
Hope this helps!
Ram - SharePoint Architect
Blog - SharePointDeveloper.in
Please vote or mark your question answered, if my reply helps you -
How to find out Db name of perticular web application in sharepoint 2010
how to find out Db name of perticular web application in sharepoint 2010 to take a backup from sql
1. Open the SharePoint 2010 Central Admin application.
2. On the SharePoint central administration website, click Application Management.
3. In the Databases section, click Manage Content Databases.
4. On the Manage Content Databases page, select a web application by clicking the Web Applications drop-down list and choosing a web application.
5. Can notice the available database names for the webapplication. ******************************************************************************************
Please remember to mark your question as answered &Vote helpful, if this solves/helps your problem
s p kumar -
Customizing Web Service for VC 7.10
Hi guys!
I need a big help for the topic "web services and VC".
I read the Scott's blog (The specified item was not found.) and it's great, web services working fine!
But if I would create custom web service (for example to insert google maps on vc model) what can I do?
I know, it's hard to explane all the web services technology and implementation (Java, C#, XML etc.) but if someone know some tutorial or web guides..
Thanks a lot guys!
Edited by: Andrea Davoli on Oct 21, 2008 3:39 PMHi Andrea,
I assume that you refer to VC 7.0... otherwise the question should be moved to the VC 7.1 forum...
The following blog contain also a video that show you the process in detail:
How to consume Web Services with Visual Composer 7.0
Also important SAP Notes regarding limitations, structure and pre-requisites are mentioned there.
In the SAP Help Portal you can find information about Web Services created within NetWeaver:
http://help.sap.com/saphelp_erp2005/helpdata/en/db/99c04ba22fe64f96a8651df68eab92/content.htm
Hope this helps,
Best Regards,
Luis -
Wanted to know if a stage can be defined that invokes a custom web service that returns an approval indicator. All the web services I've seen in GRC are at predetermined points or prebuilt integration sections. We need the ability for a custom web service to be invoked when this stage is encountered in the request workflow. If the web service return true, then the stage would be deemed approved and move onto the next state. thanks in advance.
Hi Brian,
You may want to post this question in the GRC forum. I'm not sure how many GRC experts will see it here.
forum: Governance, Risk and Compliance (SAP GRC)
The University Alliances program is exploring GRC for use w/in our program however we're not experts in this topic area today.
Best Regards,
Heather
Edited by: Heather Czech on Dec 4, 2009 6:12 AM -
Custom web service in opensso/AM
Hello,
What is the best way to extent opensso/AM with my custom web service? The functionality of the service is similar to Liberty IdentityManagement services, but not the same: I need to create several accounts/identities in one atomic operation, for instance. The same with delete and modify.
Is there any standard mechanism to accomplish this? Any help or pointers to resources would be great.
Thanks, Denis.You should probably use IDM and SPML to provision user accounts. Creating multiple accounts in one atomic action will be difficult to do if you use LDAP as a backend user store because most LDAP servers do not support the transaction control extension.
Maybe you are looking for
-
Since updating iTunes my new iPod touch 5th generation wont show up.
I recently updated iTunes on Friday. But now that I try to sync my iPod touch 5th generation it is not showing up in iTunes. The iPod asks if I trust this computer and I click yes but nothing happens. What should I do?
-
Image Capture and Preview: bad PDF page size
When scanning to a PDF document with Image Capture, the resulting PDF always has an enormous page size. For example, a 3"x3" image scanned at 300dpi will appear as a 12.5"x12.5" page in the PDF. Scanning at 72dpi will create the appropriate size page
-
Hello, I need help restoring my iPhone? can anyone help me with the Error 1015.. please.. ;-(
-
Is there anyway you can create a calculation to only round a number up and not down?
-
Implementing Side Navigation(Level 3 menus) using core apps
Hi all, I have created the require menu structure and its as followed Responsibility Menu | Home Page (attached to Responsibility Menu) | HTML Tab (attached to Home Page) | HTML Sub Tab (attached to HTML Tab) | HTML SideBar(attached to HTML Sub Tab)