MOSS2007自定义WebService(1)-----自定义Webservice的步骤介绍
来源:互联网 发布:软件新技术有哪些 编辑:程序博客网 时间:2024/04/18 12:51
MOSS2007自定义WebService
提到WebService,我们会想到asmx文件,那我们就从这个asmx文件开始:
1. 新建一个asmx文件,例如叫MyService.asmx,其内容如下:
<%@ WebService Language="C#" Class="MyServiceClass, MyServiceAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=722dca430e2d0190" %>
那么就从这个里面引出了一个GAC的assembly出来,那么我们进行下一步
2. 使用Visual Studio创建一个ClassLibrary的项目,并且将这个项目进行强命名,为什么要进行强命名呢,就是因为我们会将生成的dll部署到GAC中供WebService引用,然后如果要部署到GAC中就需要对项目进行强命名。那么我们就讲述一下如果对项目进行强命名。
3. 强命名主要有两种方式:
(1) 项目“右键---属性---签名---为程序集签名",不使用密码。
(2) 使用VS的Tool 命令行,使用sk –k “c:/Service.snk”,然后使用这个snk文件对项目进行强命名即可
4. 这一步我们主要是讲一些这个Webservice的项目内容,如何类编写
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.SharePoint.Utility;
using Microsoft.SharePoint;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyService : System.Web.Services.WebService
{
public MyService () { }
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
这里需要指出的就是继承WebService类,方法是用[WebMethod]特性即可。
5. 生成静态发现文件service.disco和Webservice的描述文件service.wsdl
(1)将service.asmx拷贝到c:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/template/layouts目录下,然后打开VS2005的命令行工具,使用如下命令:
disco http://chris/_layouts/Service.asmx
来生成service.disco和service.wsdl文件
(2)将service.disco和service.wsdl文件中的<?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" %>
<%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<% Response.ContentType = "text/xml"; %>
实际上就是把原来的纯xml变换成为一个page来解析。并且这个页面的解析是通过moss来自动处理的,是不需要我们关心的,也就是说对我们是透明的。
(3)将service.disco中的
<contractRef ref=http://chris/_layouts/service.asmx?wsdl
docRef="http://carysun/_layouts/service.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<soap address="http://chris/_layouts/service.asmx" xmlns:q1=http://tempuri.org/
binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap address=http://chris/_layouts/service.asmx xmlns:q2=http://tempuri.org/
binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
替换为:
<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://schemas.microsoft.com/sharepoint/soap/" binding="q1:HostServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q2="http://schemas.microsoft.com/sharepoint/soap/" binding="q2:HostServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
(4)将service.wsdl中的
<soap:address location="http://chris/_layouts/service.asmx" />和
<soap12:address location="http://chris/_layouts/service.asmx" />
替换为:
<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可以在运行时根据动态的请求来定位。
(1)将service.disco和service.wsdl改名为servicedisco.aspx和servicewsdl.aspx
6. 部署WebService
主要是将service.asmx,servicedisco.aspx和servicewsdl.aspx拷贝到C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/ISAPI这个目录中,然后将我们项目生成的dll部署到GAC中即可
7. 调用WebService
使用浏览器访问http://chris/_vti_bin/serivce.asmx 即可看到 Service中提供的方法,然后可以进行调用。
以上就是我们在MOSS2007中自定义WebService的过程,希望对大家有所帮助。
- MOSS2007自定义WebService(1)-----自定义Webservice的步骤介绍
- 在MOSS2007中开发并部署自定义WebService
- 自定义WebService 的 DataBinding
- MOSS2007的自定义字段类型
- webservice 返回自定义xml
- webservice 传递自定义类
- webService 自定义拦截器
- 创建具有属性值的MOSS2007自定义字段实例(包括步骤与源代码)
- WebService中使用自定义类的解决方法
- 关于WebService传递自定义对象的问题
- WebService中使用自定义类的解决方法
- WebService中使用自定义类的解决方法
- WebService中使用自定义类的解决方法
- webService返回自定义类型的数据处理
- WebService中使用自定义类的解决方法
- android开发调用自定义的webservice
- WebService中使用自定义类的解决方法
- webservice简介及发布自定义的服务
- ucosII消息队列创建函数
- X86之操作系统之DPL,RPL,CPL的区别与联系
- 软件工程——第七章 软件维护
- Ext grid自动宽度
- float和double在的存储方式
- MOSS2007自定义WebService(1)-----自定义Webservice的步骤介绍
- Linux内核同步3-RCU
- oracle的管理工具OEM以及重建索引
- 软件工程——第八章 用户界面设计(一)
- (myls)模拟" ls "命令
- linux root 密码忘了怎么办?
- 脱机安装Silverlight Tools(2.0)
- 基于CUDA的光线跟踪算法
- 使用客户端脚本(RegisterClientScriptBlock ,RegisterStartupScript )