科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道SharePoint Web Service系列:编写自定义SharePoint Web Services之一 (2)

SharePoint Web Service系列:编写自定义SharePoint Web Services之一 (2)

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

学习创建自定义SharePoint Web services ,并建立基于SharePoint 的文档上载Web servicefor用来实现外部应用程序远程访问文档库中的文档。

作者:sunmoonfire 来源:blog 2007年9月3日

关键字: SharePoint2007 SharePoint web Service Office

  • 评论
  • 分享微博
  • 分享邮件

编写一个自定义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_Name\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\bin

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章