在MOSS中添加自定义的WebService
(由于项目时间紧,没能排好版,等以后有空在重新排下版,大家凑合看着吧.)
因为要在infopath中建立一个基于web服务的表单摸板,需要在MOSS中建立自定义的WebService.
在园子里看到这篇文章SharePoint Web Service系列:编写自定义SharePoint Web Services之一 ,照着做了做,没有成功,后来仔细看看原文,是在sps2003中做的,其中的步骤"修改 Service1disco.aspx和Service1wsdl.aspx使其支持服务虚拟化机制"不太适用用在MOSS中修改,索性打开了MOSS中自带的一个WebService的相关文件,照着文件中的内容进行修改,总算是发布成功了.在这里把需要修改的地方记录一下:
一 Service1disco.aspx
1.<?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"; %>
2.<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 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/" />
3.
<soap:address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> xmlns:q1="http://tempuri.org/" binding="q1:Service1Soap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap:address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, SPWeb.OriginalBaseUrl(Request), '"'); %> xmlns:q2="http://tempuri.org/" binding="q2:Service1Soap12" xmlns="http://schemas.xmlsoap.org/disco/soap/"/>
修改为:
<soap:address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q1="http://gymstc.org/" binding="q1:Service1Soap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap:address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q2="http://gymstc.org/" binding="q2:Service1Soap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
二 Service1wsdl.aspx
1.<?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"; %>
2.
<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 location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />
-------------------------------------------------------------------------------------------------------------------------------------------------------------
<soap12: 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/" />
修改为
<soap12:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />
三 spdisco.aspx
最后一行</discovery>上添加如下代码
<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/Service1.asmx?wsdl", Response.Output); %> docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/Service1.asmx", Response.Output); %> xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<discoveryRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(spWeb.Url + "/_vti_bin/Service1.asmx?disco"),Response.Output); %> xmlns="http://schemas.xmlsoap.org/disco/" />
四 拷贝对应的.dll文件到网站所在的根目录下的bin虚拟目录中,而不是原文中的_vti_bin/bin虚拟目录。
总结:
上面看上去是修改了很多代码,实际上主要是修改了两个地方:
1 .<?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"; %>
2.把webservice的发布地址(如http://server_name:New_Port/Project_Name/Service1.asmx)修改为可以在MOSS中发布的地址即可.
(自己都感觉到有点乱,以后再整理了.^_^)