编写一个SharePoint 自定义Web服务

编写一个SharePoint 自定义Web服务

1、 在开发用网站上使用VS.NET利用其提供的模板创建一个空的 ASP.Net Web Service项目,其中将包括一个Service1.asmx 文件。

2、 进入代码编辑,移除下面的行的注释后编译该项目。

 
 

//[WebMethod]
//public string HelloWorld()
//{
//  return "Hello World";
//}

3、 现在,我们可以将我们的服务部署到WSS网站中。

 要想将自定义的Web服务绑到WSS上,VS .NET需要一些特定的基于.disco.wsdl文件的.aspx文件。首先使用VS .NET命令行工具生成我们需要的.disco.wsdl文件。

创建并编辑.disco.wsdl文件

使用VS .NET命令行工具在当前目录中生成Service1.disco Service1.wsdl,命令如下:

Disco http://server_name:New_Port/Project_Name/Service_1.asmx

打开Service1.disco文件并定位到下面的行:

<?xml version="1.0" encoding="utf-8"?>

将其替换成:

 
 

<%@ Page Language="C#" Inherits="System.Web.UI.Page"%> <%@ Assembly Name="Microsoft.SharePoint, Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint.Utilities" %> <%@ Import Namespace="Microsoft.SharePoint" %>
<% Response.ContentType = "text/xml"; %>

Service1disco.aspx保存该文件。

Service1.wsdl也进行同样的修改并保存为Service1wsdl.aspx

修改 Service1disco.aspxService1wsdl.aspx使其支持服务虚拟化机制

打开Service1disco.aspx文件并定位到下面的行:

 
 

<contractRef  ref="http://server_name:New_Port/Project_Name/Service1.asmx?wsdl" docRef=
"http://server_name:New_Port/Project_Name/Service1.asmx"
 xmlns="http://schemas.xmlsoap.org/disco/scl/" />

对标签<contractRef>进行如下修改:

 
 

<contractRef ref=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request)
 + "?wsdl", '"'); %
> docRef=<% SPEncode.WriteHtmlEncodeWithQuote(Response,
 SPWeb.OriginalBaseUrl(Request), '"'); %
>  xmlns="http://schemas.xmlsoap.org/disco/scl/" />

定位到下面的行:

 
 

<soap address="http://server_name:New_Port/Project_Name/Service1.asmx" xmlns:q1="http://tempuri.org/" binding="q1:Service1Soap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

修改<soap address> 标签为:

 

<soap address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> xmlns:q1="http://tempuri.org/" binding="q1:Service1Soap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

 

保存所有更改。

打开Service1wsdl.aspx文件并定位到下面的行:

<soap:address location="http://server_name:New_Port/Project_Name/Service1.asmx" />

修改soap:address行为:

 
 

<soap:address location=<% SPEncode.WriteHtmlEncodeWithQuote(Response,
 SPWeb.OriginalBaseUrl(Request), '"'); %
> />

保存所有更改。

Web Service相关文件拷贝到_vti_bin虚拟目录

拷贝Service1wsdl.aspx,Service1disco.aspxService1.asmx_vti_bin虚拟目录。该目录是默认的Web服务存放目录。

拷贝对应的.dll文件到_vti_bin/bin虚拟目录。

注意:_vti_bin/bin虚拟目录映射到物理路径Server_NameProgram FilesCommon FilesMicrosoft

posted @ 2010-07-22 18:32  moonwebmast  阅读(291)  评论(0编辑  收藏  举报