SharePoint使用BCS开发你第一个应用程序(四)

SharePoint使用BCS开发你第一个应用程序(四)

        很多时候,你想将IIS(Internet Information Services)中的Web Services和外部列表集成。这里教你创建ASP.NET Web Service,部署到IIS,然后在SharePoint Designer中创建外部内容类型。
1. 打开VS--文件--新建--网站,选择.NET Framework 3.5,然后选择ASP.NET Web Service。
2. 默认文件系统,给Web Service提供位置,点击确定。默认名称Service.asmx。
3. 导航到App_Code文件夹,右击Service.cs--查看代码。
4. 修改代码。它将创建Customers列表集合,添加三个记录。当应用程序调用GetCustomers方法时,返回带有三个记录的数据源。调用GetACustomer方法时,基于输入的字符串参数,返回一个记录。代码是这样的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service()
    {
    }
    public class Customers
    {
        public string customerID { get; set; }
        public string Title { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public string EmailAddress { get; set; }
        public string Phone { get; set; }
    }
    [WebMethod]
    public Customers[] GetCustomers()
    {
        List
    
    
     
      myCustomers = new List
     
     
      
      ();
        Customers customerOne = new Customers();
        customerOne.customerID = "1";
        customerOne.Title = "Dr.";
        customerOne.FirstName = "John";
        customerOne.MiddleName = "Daley";
        customerOne.LastName = "Doe";
        customerOne.EmailAddress = "john.doe@acme.com";
        customerOne.Phone = "(202) 555-1234";
        myCustomers.Add(customerOne);
        Customers customerTwo = new Customers();
        customerTwo.customerID = "2";
        customerTwo.Title = "Ms.";
        customerTwo.FirstName = "Jane";
        customerTwo.MiddleName = "Karen";
        customerTwo.LastName = "Doe";
        customerTwo.EmailAddress = "jane.doe@acme.com";
        customerTwo.Phone = "(202) 555-1233";
        myCustomers.Add(customerTwo);
        Customers customerThree = new Customers();
        customerThree.customerID = "3";
        customerThree.Title = "Mr.";
        customerThree.FirstName = "Kenneth";
        customerThree.MiddleName = "James";
        customerThree.LastName = "Staple";
        customerThree.EmailAddress = "ken@acme.com";
        customerThree.Phone = "(202) 555-1884";
        myCustomers.Add(customerThree);
        return myCustomers.ToArray();
    }
    [WebMethod]
    public Customers GetACustomer(string customerID)
    {
        Customers returnCust = new Customers();
        if (customerID == "1")
        {
            returnCust.customerID = "1";
            returnCust.Title = "Dr.";
            returnCust.FirstName = "John";
            returnCust.MiddleName = "Daley";
            returnCust.LastName = "Doe";
            returnCust.EmailAddress = "john.doe@acme.com";
            returnCust.Phone = "(202) 555-1234";
        }
        else if (customerID == "2")
        {
            returnCust.customerID = "2";
            returnCust.Title = "Ms.";
            returnCust.FirstName = "Jane";
            returnCust.MiddleName = "Karen";
            returnCust.LastName = "Doe";
            returnCust.EmailAddress = "jane.doe@acme.com";
            returnCust.Phone = "(202) 555-1233";
        }
        else if (customerID == "3")
        {
            returnCust.customerID = "3";
            returnCust.Title = "Mr.";
            returnCust.FirstName = "Kenneth";
            returnCust.MiddleName = "James";
            returnCust.LastName = "Staple";
            returnCust.EmailAddress = "ken@acme.com";
            returnCust.Phone = "(202) 555-1884";
        }
        return returnCust;
    }
}

     
     
    
    
5. 点击F5,启用调试。

        你可以点击任何一个Web 方法(GetCustomers或GetACustomer)。如果点击了GetCustomers,页面是这样的:

6. 如果调试成功,则停止调试。右击项目--发布网站。选择文件系统,浏览到你想部署Web服务的文件夹。接受默认,点击确定。

7. 你现在需要映射发布的项目到IIS。点击开始--管理工具--IIS。右击网站,添加新网站GetCustomerWS。确保虚拟路径指向你发布服务的地址。必须提供非80的端口,如1141.可选的你可以提供主机名。点击连接为--指定用户,设置添加你的密令作为服务用的用户。

点击确定完成。点击测试设置来测试你的密令和服务调用。

8. 确保Windows认证启用。点击身份验证,启用Windows身份验证。

9. 在IIS中测试服务。点击浏览,可以找到对应Service.asmx文件。

10. 打开SharePoint Designer--外部内容类型。新建一个。
11. 命名CustomerWS,显示名Customer WS,联系人,点击发现数据源--WCF Service。
12. 输入URL--http://smallville-pc:1141/Service.asmx?wsdl到服务元数据URL;和服务节点URL(没有?wsdl)。

13. 点击确定。
14. 右击GetACustomer方法--新建“读取项”操作。点击下一步。

15. 选中customerID,映射到标识符。点击下一步。对数据进行映射,点击完成。

16. 你必须配置新读取列表操作。右击GetCustomers方法,新建读取列表操作。点击下一步两次。点击customerID映射为标识符。点击完成。

17. 点击保存。这样就保存外部内容类型到BDC元数据仓库。
        此时你可以创建外部列表了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值