惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
D
Docker
H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
C
Check Point Blog
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
M
MIT News - Artificial intelligence
B
Blog RSS Feed
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
美团技术团队
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale

博客园 - 翅膀

WCF测试机部署服务器 .net 操作 EXCEL OpenXML 替换word模板中的标签 AgilePoint BPMS 业务流程 List中插入超链接栏 结合eventHanlder和openXMl 实现上传word文档加页眉,页脚 InfoPath 上传多附件解决方法 moss 自定义文档库文档图标 Microsoft Office SharePoint Server 2007的文件目录结构 常用的stsadm命令行参数 如何隐藏“查看所有网站内容” 查看SharePoint未知错误 Layouts里的页面应用站点母板页 MOSS和其他系统的数据集成方式 MOSS中获取当前用户信息 关于MOSS中,用代码实现在列表中新增一列为增强型的RichTextField 自定义字段类型的开发[转] C#.net中操作XML SharePoint Web Service系列:编写自定义SharePoint Web Services之一
SharePoint Web Service系列:编写自定义SharePoint Web Serv...
翅膀 · 2008-09-04 · via 博客园 - 翅膀

面,我们要将我们的Web服务添加到WSS的Web服务列表中,这样就可以在VS.NET中添加该Web服务的引用了。

1、打开spdisco.aspx文件,该文件位于Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\ISAPI目录。

2、在文件末尾的discovery元素中添加下面的内容,保存。

<contractRef ref=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + "/_vti_bin/Service1.asmx?wsdl", '"'); %> docRef=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + "/_vti_bin/Service1.asmx", '"'); %> xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<soap address=<% SPEncode.WriteHtmlEncodeWithQuote(Response, spWeb.Url + "/_vti_bin/Service1.asmx", '"'); %>
 xmlns:q1="http://schemas.microsoft.com/sharepoint/soap/directory/" binding="q1:Service1Soap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

注意:soap元素的binding属性中在 "Soap"之前的文字(该例中的binding="q1:Service1Soap")指定了定义Web service时使用的类名。

 至此,我们的自定义Web service就部署完成了。我们可以像使用默认的Web service一样来调用我们的自定义Web service了。

创建文档上载Web服务

我们可以使用上面的方法来建立文档上载Web服务来上载文档到一个WSS的共享文档文档库。该服务利用服务虚拟化来获取站点上下文,然后上载文档到指定的文档库。

创建一个Web service项目,名为UploadSvc。添加一个新的Web service类命名为UploadFile

添加对Windows SharePoint Services (Microsoft.Sharepoint.dll)的引用。

UploadFile类中添加下面的Web方法:

[WebMethod]
public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
{
    
if ( fileContents == null)
    {
        
return "Null Attachment";
    }
   
try
   {
        SPWeb site 
= SPControl.GetContextWeb(Context);
        SPFolder folder 
= site.GetFolder(pathFolder);
        
string fileUrl = fileName;
        SPFile file 
= folder.Files.Add(fileUrl, fileContents);
        
return file.TimeCreated.ToLongDateString()+ "::" + file.Title;
   }
   
catch (System.Exception ee)
    {
        
return ee.Message + "::" + ee.Source;
    }
}

添加下面的命名空间引用:

using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

编译该Web service项目。

创建并修改.disco和.wsdl并修改spdisco.aspx, 需要将上面的Service1 替换成UploadFile。分别保存为UploadFiledisco.aspx和UploadFilewsdl.aspx

拷贝这些文件到_vti_bin, 拷贝对应得.dll到 _vti_bin/bin。

调用上载文件服务的例子

新建一个WinForm应用程序,添加Web引用,并将该引用命名为WSSServer

添加一个button和两个textbox到默认的窗体,一个textbox用来输入上载文件的路径,另一个用来指定要上载到哪个文档库。如http://Server_Name/sites/Target_Site/Document_Library

添加下面的代码到button的Click事件中。

WSSServer.UploadFile svcDocLib = new WSSServer.UploadFile();
svcDocLib.Credentials 
= CredentialCache.DefaultCredentials;string strPath = textBox1.Text;
string strFile = strPath.Substring(strPath.LastIndexOf("\\"+ 1);
string strDestination = textBox2.Text;
 
FileStream fStream 
= new FileStream(strPath, System.IO.FileMode.Open);
byte[] binFile = new byte[(int)fStream.Length];
fStream.Read(binFile, 
0, (int)fStream.Length);
fStream.Close();
 
string str = svcDocLib.UploadDocument(strFile, binFile, strDestination);
MessageBox.Show(str);

添加命名空间引用:

using System.Net;
using System.IO;

编译运行。