Dailycode.info

Short solution for short problems

Using webservices in a webpart

I'm developing webparts not on the server, but a simple develop machine. It is not possible to use the visual studio Web part extensions. So I create and copy the whole thing myself.

No big problems there. But then come the choice, adding the assembly to the GAC or not? I choose not to, because of security reasons. I just copy my DLL to the bin folder of the virtual directory. Works fine, I did had to put the web.config to medium trust and add this line to the web.config:

<SafeControl Assembly="SOP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=93464d75f4108077" 
Namespace="MYNAMESPACE" TypeName="*" Safe="True" AllowRemoteDesigner="True" />
 

Don't forget to add the webpart, you can do this when you choose site settings and click on webparts.

When I started working with webservices in the webpart, it became a lillte more difficult. But thanks to google and some collegue programmers I solved this lovely exception:

System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, 
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 

This site explains it good: http://store.bamboosolutions.com/kb/article.aspx?id=10405 

I extracted the steps you'll have to take in order to clear up this error:

You'll have to add these lines to the medium trust file (or a custom trust file): 

<IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1"> 
<ConnectAccess>  
<URI uri="http://myserver:myport/mysitecollection\mywebservice.asmx"/
</ConnectAccess>
</IPermission>
 

The path of the trust files can be found in the web.config. In my case it was:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG
 

You can add multiple url's!


UpdateListItems

I'm developing a webpart that uses the WSS webservices to update en create list items.

Using the UpdateListItems method from the Lists webservice, it is possible to add or update listitems. I google a few minutes and came up with this solution:

try
{
	string sListName = "SOP response";
	string sSOPName = this.Page.Request.QueryString["qSOPName"];
	SOP.SPSLists.Lists list = new SOP.SPSLists.Lists();
	list.Url = "http://pmibeleudb02:777/SOP/_vti_bin/Lists.asmx";
	list.Credentials = System.Net.CredentialCache.DefaultCredentials;
	XmlDocument xmlDoc = new System.Xml.XmlDocument();
	System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
	StringBuilder sb = new StringBuilder();
	sb.Append(@"<Method ID='1' Cmd='New'>");
	sb.Append(@"<Field Name='SOPName'>MarkSOP</Field>");
	sb.Append(@"<Field Name='Employee'>Mark</Field>");
	//sb.Append(@"<Field Name='Date' />");
	//sb.Append(@"<Field Name='EventDate' />");
	sb.Append(@"</Method>");
 
	elBatch.SetAttribute("OnError", "Continue");
	elBatch.SetAttribute("ListVersion", "1");
	elBatch.InnerXml = sb.ToString();
	XmlNode returnNod = list.UpdateListItems(sListName, elBatch);
 
}
catch (Exception er)
{
	_mylabel.Value = er.Message;
}
 

Then this error occured:

0x81020014One or more field types are not installed properly. Go to the list settings page to delete these fields.
 

This error was because I changed the Title field to SOPName, but the CAML name is still Title. If you have a simular problem but you can't find the caml name of the field, click to edit the field and look in the url at the end, there should be the CAML name of the field. When I used Title instead of SOPName it worked!

http://my server/SOP/_layouts/FldEdit.aspx?List=%7BB5343477%2D48A4%2D4C37%2D953A%2D153B7B2288E1%7D&Field=Title


WSS 3.0 Webservices

Here is a list of all webservices and their functions:

Below is a list of all WSS 3.0 web services and their methods. This is not intended to be comprehensive documentation of each service and its methods. This is simply a quick list of web methods intended to simplify the process of finding a particular method.

Web Service
Methods

Admin Web Service
http://<AdminSite>/_vti_adm/Admin.asmx
Provides methods for managing a deployment of Microsoft Windows SharePoint Services, such as for creating or deleting site collections.
CreateSite
DeleteSite
GetLanguages
RefreshConfigCache


Alerts
http://<Site>/_vti_bin/Alerts.asmx
Provides methods for working with alerts for list items in a SharePoint site.
DeleteAlerts
GetAlerts


Authentication
http://<Site>/_vti_bin/Authentication.asmx
Login
Mode


Copy
http://<Site>/_vti_bin/Authentication.asmx
Provides methods for copying files to or from or within a SharePoint site.
CopyIntoItems
CopyIntoItemsLocal
GetItem


Document Workspace
http://<Site>/_vti_bin/Dws.asmx
Exposes methods for managing Document Workspace sites and the data they contain.
CanCreateDwsUrl
CreateDws
CreateFolder
DeleteDws
DeleteFolder
FindDwsDoc
GetDwsData
GetDwsMetaData
RemoveDwsUser
RenameDws
UpdateDwsData


Forms
http://<Site>/_vti_bin/Forms.asmx
Provides methods for returning forms that are used in the user interface when working with the contents of a list.
GetForm
GetFormCollection


Imaging
http://<Site>/_vti_bin/Imaging.asmx
Provides methods that enable you to create and manage picture libraries.
CheckSubwebAndList
CreateNewFolder
Delete
Download
Edit
GetItemsByIds
GetItemsXMLData
GetListItems
ListPictureLibrary
Rename
Upload


List Data Retrieval (StsAdapter)
http://<Site>/_vti_bin/DspSts.asmx
Represents the adapter service used to perform queries against sites and lists in Microsoft Windows SharePoint Services.
Query


Lists
http://<Site>/_vti_bin/Lists.asmx
Provides methods for working with lists and list data.
AddAttachment
AddDiscussionBoardItem
AddList
AddListFromFeature
ApplyContentTypeToList
CheckInFile
CheckOutFile
CreateContentType
DeleteAttachment
DeleteContentType
DeleteContentTypeXmlDocument
DeleteList
GetAttachmentCollection
GetList
GetListAndView
GetListCollection
GetListContentType
GetListContentTypes
GetListItemChanges
GetListItemChangesSinceToken
GetListItems
GetVersionCollection
UndoCheckOut
UpdateContentType
UpdateContentTypesXmlDocument
UpdateContentTypeXmlDocument
UpdateList
UpdateListItems


Meetings
http://<Site>/_vti_bin/Meetings.asmx
Enables you to create and manage Meeting Workspace sites.
AddMeeting
AddMeetingFromICal
CreateWorkspace
DeleteWorkspace
GetMeetingsInformation
GetMeetingWorkspaces
RemoveMeeting
RestoreMeeting
SetAttendeeResponse
SetWorkspaceTitle
UpdateMeeting
UpdateMeetingFromICal


People
http://<Site>/_vti_bin/People.asmx
ResolvePrincipals
SearchPrincipals


Permissions
http://<Site>/_vti_bin/Permissions.asmx
Provides methods for working with the permissions for a site or list.
AddPermission
AddPermissionCollection
GetPermissionCollection
RemovePermission
RemovePermissionCollection
UpdatePermission


Site Data
http://<Site>/_vti_bin/SiteData.asmx
Provides methods that return metadata or list data from sites or lists in Microsoft Windows SharePoint Services.
EnumerateFolder
GetAttachments
GetChanges
GetContent
GetList
GetListCollection
GetListItems
GetSite
GetSiteAndWeb
GetSiteUrl
GetURLSegments
GetWeb


Sites
http://<Site>/_vti_bin/Sites.asmx
Provides a method for returning information about the collection of site templates on the virtual server.
ExportWeb
GetSiteTemplates
GetUpdatedFormDigest
ImportWeb


Search
http://<Site>/_vti_bin/spsearch.asmx
The QueryService class is the entry point for calling the Search in Microsoft Windows SharePoint Services Query web service.
GetPortalSearchInfo (MOSS only)
GetSearchMetadata (MOSS only)
Query
QueryEx
RecordClick (MOSS only)
Registration
Status


Users and Groups
http://<Site>/_vti_bin/usergroup.asmx
Provides methods for working with users, role definitions, and groups.
AddGroup
AddGroupToRole
AddRole
AddRoleDef
AddUserCollectionToGroup
AddUserCollectionToRole
AddUserToGroup
AddUserToRole
GetAllUserCollectionFromWeb
GetGroupCollection
GetGroupCollectionFromRole
GetGroupCollectionFromSite
GetGroupCollectionFromUser
GetGroupCollectionFromWeb
GetGroupInfo
GetRoleCollection
GetRoleCollectionFromGroup
GetRoleCollectionFromUser
GetRoleCollectionFromWeb
GetRoleInfo
GetRolesAndPermissionsForCurrentUser
GetRolesAndPermissionsForSite
GetUserCollection
GetUserCollectionFromGroup
GetUserCollectionFromRole
GetUserCollectionFromSite
GetUserCollectionFromWeb
GetUserInfo
GetUserLoginFromEmail
RemoveGroup
RemoveGroupFromRole
RemoveRole
RemoveUserCollectionFromGroup
RemoveUserCollectionFromRole
RemoveUserCollectionFromSite
RemoveUserFromGroup
RemoveUserFromRole
RemoveUserFromSite
RemoveUserFromWeb
UpdateGroupInfo
UpdateRoleDefInfo
UpdateRoleInfo
UpdateUserInfo


Versions
http://<Site>/_vti_bin/Versions.asmx
Provides methods for working with file versions.
DeleteAllVersions
DeleteVersion
GetVersions
RestoreVersion


Views
http://<Site>/_vti_bin/Views.asmx
Provides methods for working with views of lists.
AddView
DeleteView
GetView
GetViewCollection
GetViewHtml
UpdateView
UpdateViewHtml
UpdateViewHtml2


Web Part Pages
http://<Site>/_vti_bin/WebPartPages.asmx
Provides methods for working with Web Parts.
AddWebPart
AddWebPartToZone
AssociateWorkflowMarkup
ConvertWebPartFormat
DeleteWebPart
ExecuteProxyUpdates
FetchLegalWorkflowActions
GetAssemblyMetaData
GetBindingResourceData
GetCustomControlList
GetDataFromDataSourceControl
GetFormCapabilityFromDataSourceControl
GetSafeAssemblyInfo
GetWebPart
GetWebPart2
GetWebPartCrossPageCompatibility
GetWebPartPage
GetWebPartPageConnectionInfo
GetWebPartPageDocument
GetWebPartProperties
GetWebPartProperties2
GetXmlDataFromDataSource
RemoveWorkflowAssociation
RenderWebPartForEdit
SaveWebPart
SaveWebPart2
ValidateWorkflowMarkupAndCreateSupportObjects


Webs
http://<Site>/_vti_bin/Webs.asmx
Provides methods for working with sites and subsites.
CreateContentType
CustomizeCss
DeleteContentType
GetActivatedFeatures
GetAllSubWebCollection
GetColumns
GetContentType
GetContentTypes
GetCustomizedPageStatus
GetListTemplates
GetWeb
GetWebCollection
RemoveContentTypeXmlDocument
RevertAllFileContentStreams
RevertCss
RevertFileContentStream
UpdateColumns
UpdateContentType
UpdateContentTypeXmlDocument
WebUrlFromPageUrl