1、在Visual Studio 2008中创建 ASP.NET Web 服务应用程序。
2、在项目中添加新建项:[web服务]:Profile.asmx
3、编码:

Code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
namespace Simone.SharePoint.WebService
{
/// <summary>
/// Profile 的摘要说明
/// </summary>
[WebService(Namespace = "http://webservice.sharepoint.simone.net.cn/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Profile : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
4、编译(F5),预览一下 Profile Web 服务。PS:不要关闭ASP.NET Development Server。
5、在Visual Studio 2008 命令行中输入:
disco http://localhost:15233/Profile.asmx
PS:15233是您Visual Studio开发服务器随即自动分配的端口号。
6、将生成的Profile.disco、Profile.wsdl改名为Profiledisco.aspx、Profilewsdl.aspx
7、打开Profiledisco.aspx、Profilewsdl.aspx,在两个页面中将:
<?xml version="1.0" encoding="utf-8"?>
更改为:
<%@ Page Language="C#" Inherits="System.Web.UI.Page" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<% Response.ContentType = "text/xml"; %>
将所有:
"http://localhost:15233/Profile.asmx"
更改为:
<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
在Profilewsdl.aspx中,将:
"http://localhost:15233/Profile.asmx?wsdl"
更改为:
<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %>
8、在Profile.asmx上点击右键,查看标记,去掉:
CodeBehind="Profile.asmx.cs"
9、在_layouts文件夹中创建WebService文件夹,将Profile.asmx、Profiledisco.aspx、Profilewsdl.aspx复制到此文件夹。将Simone.SharePoint.WebService.dll复制到C:\inetpub\wwwroot\wss\VirtualDirectories\[端口]\bin文件夹中。
10、在[端口]下的应用程序创建的网站集及网站中访问_layouts/WebService/Profile.asmx,我们就可以访问我们创建的WebService了。