如何在Dynamic CRM 2013中建立WebService介面供其它系統調用

來源:互聯網
上載者:User

標籤:

由於MSCRM的異構性和封閉性,許多其它的平台無法直接調用MSCRM提供的API介面,一般的處理方式是用.net編寫webservice,通過中間這一層轉換來使其它系統調用我們自己編寫的webservice.下面示範如何開發可調用MSCRM2013 API的webservice。

主要步驟:

  1. 建立asp.net web項目
  2. 編寫代碼
  3. 驗證服務
  4. 產生項目,並將相關檔案拷貝到CRM的指定路徑

一.建立項目


右鍵點擊資源管理員項目,並添加一個web服務,此處名稱為:MSCRMWebServiceDemo


引用相關的DLL檔案



二.編寫代碼

using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Client;using Microsoft.Xrm.Sdk.Query;using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.ServiceModel.Description;using System.Web;using System.Web.Services;namespace MSCRMWebServiceDemo{    /// <summary>    /// MyMSCRMWebService 的摘要說明    /// </summary>    [WebService(Namespace = "http://tempuri.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    [System.ComponentModel.ToolboxItem(false)]    // 若要允許使用 ASP.NET AJAX 從指令碼中調用此 Web 服務,請取消注釋以下行。     // [System.Web.Script.Services.ScriptService]    public class MyMSCRMWebService : System.Web.Services.WebService    {        static private IOrganizationService GetOrganisationService()        {            ClientCredentials credentials = new ClientCredentials();            credentials.Windows.ClientCredential = new NetworkCredential("crmadmin", "password01!", "test");            OrganizationServiceProxy proxy = new OrganizationServiceProxy(new Uri("http://192.168.10.17/test/XRMServices/2011/Organization.svc"), null, credentials, null);            return proxy as IOrganizationService;        }        [WebMethod]        public string HelloWorld()        {            IOrganizationService service = GetOrganisationService();           //用FETCHXML的方式擷取會員資料            string fetch2 = @"   <fetch mapping='logical'>  <entity name='account'>    <attribute name='name' />    <attribute name='address1_city' />    <attribute name='primarycontactid' />    <attribute name='telephone1' />    <attribute name='accountid' />    <order attribute='name' descending='false' />    <link-entity name='contact' from='contactid' to='primarycontactid' visible='false' link-type='outer' alias='accountprimarycontactidcontactcontactid'>      <attribute name='emailaddress1' />    </link-entity>  </entity></fetch>";            EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetch2));            String name = "";            foreach (var c in result.Entities)            {                name += c.Attributes["name"];            }            return name;        }    }}
三.點擊VS的運行按鈕,測試服務




四.部署相關項目至CRM指定路徑

拷貝MSCRMWebServiceDemo.dll至CRM的以下路徑:

X:\Program Files\Microsoft Dynamics CRM\CRMWeb\bin

拷貝MyMSCRMWebService.asmx至CRM的以下路徑:

C:\Program Files\Microsoft Dynamics CRM\CRMWeb\ISV

最後驗證一下webservice,開啟如下地址,出現以下介面則部署成功




如何在Dynamic CRM 2013中建立WebService介面供其它系統調用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.