MOSS2010中如何使用自定义WebService
2012-11-30 15:29
387 查看
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
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
修改为
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
BPMServices.disco的【如下部分】修改为BPMServicedisco.aspx
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
修改为
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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站点,因此需要设置访问的账号
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
注意:
Sharepoint2010缺省关闭了ASP.NET Webservice的访问支持,在访问以前需要把asmx文件类型的阻塞过滤删掉。操作方法Central Administration→Security→Define blocked file types→删除asmx文件类型→保存。
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>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
修改为
<%@ 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"; %> …………… …………… …………… <wsdl:service name="BPMDocService"> <wsdl:port name="BPMDocServiceSoap" binding="tns:BPMDocServiceSoap"> <soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> /> </wsdl:port> <wsdl:port name="BPMDocServiceSoap12" binding="tns:BPMDocServiceSoap12"> <soap12:address location=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> /> </wsdl:port> </wsdl:service>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
修改为
<%@ 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"; %> <discovery xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.xmlsoap.org/disco/"> <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://tempuri.org/" binding="q1:HelloWorld" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> <soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> </discovery>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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");
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
注意:
Sharepoint2010缺省关闭了ASP.NET Webservice的访问支持,在访问以前需要把asmx文件类型的阻塞过滤删掉。操作方法Central Administration→Security→Define blocked file types→删除asmx文件类型→保存。
相关文章推荐
- MOSS2010如何使用Linq进行分页
- MOSS中如何自定义WebService
- MOSS中如何自定义WebService
- MOSS中如何自定义WebService
- [MOSS 译]如何:在WEB内容查询部件中使用自定义的字段
- 利用webservice.htc如何使用Soap标头自定义身份验证和授权
- MOSS中如何自定义WebService
- 【MOSS 2010】 如何开发一个自定义的WebPart来承载Silverlight应用程序
- 【MOSS 2010】 如何开发一个自定义的WebPart来承载Silverlight应用程序
- MOSS中使用自定义WebService
- 搜索应用一:在自定义DisplayForm中使用Moss搜索(精简版).
- 实例演示如何使用AgileEAS.NET SOA平台工作流进行业务流程自定义
- SharePoint 2010 使用自定义aspx页面替换列表默认的新建(NewForm.aspx),查看(DispForm.aspx)和编辑(EditForm.aspx)页面
- 在自定义HttpHandler中如何使用Session
- 如何设计和使用自定义的权限对象(自定义权限检查函数)
- 在Activiti中如何使用自定义的组织架构
- 在asp.net webservice中如何使用session
- 如何使用Visual Studio 2010在数据库中生成随机测试数据
- 如何自定义类以及如何使用自定义类
- 如何在android style文件中使用自定义属性