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

推荐订阅源

MyScale Blog
MyScale Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
爱范儿
爱范儿
小众软件
小众软件
K
Kaspersky official blog
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
V
Vulnerabilities – Threatpost
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
C
Check Point Blog
S
Schneier on Security
P
Palo Alto Networks Blog
IT之家
IT之家
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
Y
Y Combinator Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
S
Securelist
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理

博客园 - 翅膀

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 Services之二
翅膀 · 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;

编译运行。