http://www.cnblogs.com/yungboy/archive/2009/03/31/1426285.html

步骤:
1.创建webservice
2.生成并修改.wsdl,.disco文件
3.将Web服务文件部署到 _vti_bin 目录
4.设置服务调用路径
5.调用服务

具体步骤:

1.创建webservice,编译,以SPCustomService.asmx为例
 
2.生成并修改.wsdl,.disco文件
  (1).copy webservice生成的bin到要部署的sharepoint 网站的虚拟目录bin下
  (2).打开layouts目录(layouts地址http://www.cnblogs.com/yungboy/admin/file://program/ Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS),拷贝webservice下的.asmx文件到layouts下
  (3).开始--运行,输入cmd,转向layouts目录,运行disco http://服务器:端口号/_layouts/SPCustomService.asmx(e.g.disco http://demo:8001/_layouts/SPCustomService.asmx),生成 webservice文件名.disco和webservice文件名.wsdl.若没有disco.exe文件,则需要安装microsoft sdks,打开C:/Program Files/Microsoft SDKs/Windows/v6.0A/bin,拷贝disco.exe到layouts目录下,运行disco http://服务器:端口号/_layouts/SPCustomService.asmx

 (4).修改webservice文件名.disco
 打开 .disco 和 .wsdl 文件,将开放式 XML 处理指令 <?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"; %>

  (5).在 .disco 文件中,修改合同引用和 SOAP 地址标记,使其类似于如下示例,以便通过 Microsoft.SharePoint.Utilities.SPHttpUtility 类的使用,将文本路径替换为代码生成的路径,同时替换在 binding 属性中指定的方法名称:
 <contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + "?wsdl"),Response.Output); %>
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns:q1="http://tempuri.org/" binding="q1:HelloWorld" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>
xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
 
  (6).在 .wsdl 文件中,对指定的 SOAP 地址进行以下类似的替换:
  <soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />

3.将Web服务文件部署到 _vti_bin 目录
 _vti_bin http://www.cnblogs.com/yungboy/admin/file://program/ Files/Common Files/Microsoft Shared/Web Server Extensions/12/ISAPI 目录,后者包含用于 Windows SharePoint Services 的默认 Web 服务文件。将新的 SPCustomServicewsdl.aspx 和 SPCustomServicedisco.aspx 文件及 SPCustomService.asmx 以及dll文件复制到 ISAPI 文件夹中。
4.打开位于 /Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/ISAPI 中的 spdisco.aspx 文件,并添加下面的代码,这可以为您的 Web 服务指定 .asmx 文件:
 <contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/SPCustomService.asmx?wsdl"), Response.Output); %>
docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/SPCustomService.asmx"), Response.Output); %>
xmlns=" http://schemas.xmlsoap.org/disco/scl/ " />
<discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/SPCustomService.asmx?disco"),Response.Output); %>
xmlns="http://schemas.xmlsoap.org/disco/" />

5.调用服务
 输入http://服务器:端口号/_layouts/SPCustomService.asmx,测试服务,重起IIS

参考:http://msdn.microsoft.com/zh-cn/library/ms464040.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值