1、 使用vs2012新建一个web services解决方案,因为DLL需要部署GAC中去,因此需要强签名。如下图:
2、 编写业务逻辑代码。
3、 编译发布后,需要把DLL部署到GAC中,使用如下命令行部署:
gacutil –i c:\publish\ EG.EIP.BPMWebService.dll
4、 把ASP.NET Webservice的asmx文件拷贝到%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS目录
5、 通过disco命令,生成.wsdl文件和.disco文件
disco http://moss:8001/_layouts/BPMDocService.asmx /out:c:\moss
6、 产生2个文件BPMService.wsdl,BPMServices.disco,修改.wsdl和.disco,把这两个文件另存为BPMServicewsdl.aspx和BPMServicedisco.aspx,修改分别如下:
- BPMService.wsdl的【如下部分】修改为BPMServicewsdl.aspx
<?xml version="1.0" encoding="utf-8"?> …………… …………… …………… <wsdl:service name="Service"> <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap"> <soap:address location="http://localhost:17906/MyTestWebService/Service.asmx" /> </wsdl:port> <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12"> <soap12:address location="http://localhost:17906/MyTestWebService/Service.asmx" /> </wsdl:port> </wsdl:service>
修改为
- BPMServices.disco的【如下部分】修改为BPMServicedisco.aspx
<?xml version="1.0" encoding="utf-8"?> <discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/"> <contractRef ref="http://localhost:17906/MyTestWebService/Service.asmx?wsdl" docRef="http://localhost:17906/MyTestWebService/Service.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> <soap address="http://localhost:17906/MyTestWebService/Service.asmx" xmlns:q1="http://tempuri.org/" binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> <soap address="http://localhost:17906/MyTestWebService/Service.asmx" xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> </discovery>
修改为
7、 把BPMService.asmx,BPMServicewsdl.aspx和BPMServicedisco.aspx一起拷贝部署到%ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI目录下。
8、 运行效果图:
9、 调用此web service方法
引用此web service,由于在MOSS的站点下,不是匿名的web service站点,因此需要设置访问的账号
moss.BPMDocService doc = new moss.BPMDocService();
//设置访问的账号
doc.Credentials = new NetworkCredential("administrator","Passw0rd!", "mono");
doc.Url = "http://moss:8001/_vti_bin/BPMDocService.asmx";
doc.HelloWorld(attachment, "mono\\test");
注意:
Sharepoint2010缺省关闭了ASP.NET Webservice的访问支持,在访问以前需要把asmx文件类型的阻塞过滤删掉。操作方法Central Administration→Security→Define blocked file types→删除asmx文件类型→保存。