自定义桌面web:MOSS中如何自定义WebService来源: 发布时间:星期日, 2009年2月8日 浏览:42次 评论:0
MOSS中已经提供webservice都放在虚拟目录_vti_bin中对应物理目录为c:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPI可能你会觉得这个目录_vti_bin名有点怪这个名字来自该公司Vermeer Technologies Incorporated这个公司唯产品就是FrontPage该公司在1996年被微软收购
下面我们就自己实现个webservice需要以下几步: :建立Webservice项目 1.使用vs2005建立个webserivce项目来实现我们webservice然后我在填加个类库用于实现webservice逻辑部分项目结构如下图: 为MOSSLibrary2类库签名项目“右键---属性---签名---为集签名",不使用密码Service.cs是现实Webservice逻辑地方代码如下: using ; 2:将MOSSLibrary2类库添加到GAC中 有两种思路方法: 1. 将bin目录下MOSSLibrary2.dll拖到%windows%assembly文件夹下即可 2. 打开VS2005命令行工具用GACUI.exe工具命令如下: gacutil.exe -iF "<Full file system path to DLL>". 3:修改service.asmx文件 <%@ WebService Language="C#" Class="MyServiceClass, MyServiceAssembly, Version=1.0.0.0, 其中相关信息可以到%windows%assembly文件夹下找到MOSSLibrary2.dll右键查看其属性获得该修改主要指定service.asmx逻辑文件使用是MOSSLibrary2项目中service.cs中代码 4:生成静态发现文件service.disco和Webservice描述文件service.wsdl 1.将service.asmx拷贝到c:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12templatelayouts目录下然后打开VS2005命令行工具使用如下命令: disco http://carysun/_layouts/Service.asmx 完成后会生成service.disco和service.wsdl文件 2.将service.disco和service.wsdl文件中<?xml version="1.0" encoding="utf-8"?>该语句替换为以下语句: <%@ Page Language="C#" Inherits=".Web.UI.Page" %> 实际上就是把原来纯xml变换成为个page来解析并且这个页面解析是通过moss处理 3.将service.disco中 <contractRef ref=http://carysun/_layouts/service.asmx?wsdl 替换为: <contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl 4.将service.wsdl中 替换为: <soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl (Request)),Response.Output); %> /> 和<soap12:address location=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl (Request)),Response.Output); %> /> 对于contractRef 还有soap address这两个节更改实际上是在页面里面重新编码了soap查询url这样做目也 是为了moss托管web service可以在运行时根据动态请求来正确定位 5.将service.disco和service.wsdl改名为servicedisco.aspx和servicewsdl.aspx 5:部署webservice 将servicedisco.aspxservicewsdl.aspx和service.asmx 3个文件拷贝到c:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12ISAPI目录中然后我们就可以通过以下地址来检测我们部署是否成功了http://carysun/_vti_bin/Service.asmx. 如下图: 6:客户端 我们建立个window应用添加该webservice应用然后在按钮单击事件添加如下代码: carysun.Service se= WindowsApplication1.carysun.Service; se.UseDefaultCredentials = true;这句代码是设置信任否则会报没有权限 最后效果为: 0
相关文章
读者评论发表评论 |