• MOSS2010中如何使用自定义WebService


    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目录

    clip_image002

    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>
    

    修改为

    <%@ 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>
    
    • 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>
    

    修改为

    <%@ 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>
    

    7、 把BPMService.asmx,BPMServicewsdl.aspx和BPMServicedisco.aspx一起拷贝部署到%ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI目录下。

    8、 运行效果图:

    clip_image008

    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文件类型→保存。

  • 相关阅读:
    线性单链表动态内存分配(C语言实现)
    线性顺序表动态内存分配(C语言实现)
    Linux-v01天-课堂笔记
    博客园之自定义博客(美化+播放器)
    递归练习
    算法基础练习-_06 二进制小数
    算法基础练习-_05将整数的奇偶位互换
    算法基础练习-_03 1的个数
    算法基础练习-_01找出唯一成对的数
    常用算法之快速排序
  • 原文地址:https://www.cnblogs.com/love007/p/2796306.html
Copyright © 2020-2023  润新知