代码之家  ›  专栏  ›  技术社区  ›  Mauro

CRM个人和IFD

  •  0
  • Mauro  · 技术社区  · 16 年前

    我有一个ASP.NET页面,它对于服务的内部调用很好,但是当在一个面向外部的站点上使用时,我根本无法让它工作。

    当在内部访问时,crmiPersonator工作正常,但是当使用ifd接口时,我得到的只是一条消息

    'Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' doesn't exist.
    Parameter name: Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.ArgumentException: 'Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' doesn't exist.
    Parameter name: Microsoft.Crm.WebServices.Crm2007.CookieAndSoapHeaderAuthenticationProvider, Microsoft.Crm.WebServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    

    我的代码如下

    public string orgname;
    public string crmurl;
    public string metaurl;
    public bool offline;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        #region CRM URLs and Organization Name
    
        //Determine Offline State from Host Name
        if (Request.Url.Host.ToString() == "127.0.0.1")
        {
            #region offline
            offline = true;
    
            //Retrieve the Port and OrgName from the Registry
            //RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\MSCRMClient");
            //orgname = regkey.GetValue("ClientAuthOrganizationName").ToString();
            string portnumber = regkey.GetValue("CassiniPort").ToString();
    
            //Construct the URLs
            string baseurl = "http://localhost:" + portnumber + "/mscrmservices/2007/";
            crmurl = baseurl + "crmservice.asmx";
            metaurl = baseurl + "metadataservice.asmx";
            #endregion
        }
        else
        {
            offline = false;
    
            //Retrieve the URLs from the Registry
            //RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");
            //string ServerUrl = regkey.GetValue("ServerUrl").ToString();
            string ServerUrl = "http://192.168.1.152:5555/MSCRMServices";
            crmurl = ServerUrl + "/2007/crmservice.asmx";
            metaurl = ServerUrl + "/2007/metadataservice.asmx";
            Response.Write("ServerURL " + ServerUrl + "<br>");
            Response.Write("CRMURL:   " + crmurl + "<br>");
            Response.Write("MetaURL:  " + metaurl + "<br>");
    
            //Retrieve the Query String from the current URL
            if (Request.QueryString["orgname"] == null)
            {
                orgname = string.Empty;
            }
            else
            {
                //Query String
                string orgquerystring = Request.QueryString["orgname"].ToString();
                if (string.IsNullOrEmpty(orgquerystring))
                {
                    orgname = string.Empty;
                }
                else
                {
                    orgname = orgquerystring;
                }
    
            }
    
            if (string.IsNullOrEmpty(orgname))
            {
                //Windows Auth URL
                if (Request.Url.Segments[2].TrimEnd('/').ToLower() == "isv")
                {
                    orgname = Request.Url.Segments[1].TrimEnd('/').ToLower();
                }
    
                //IFD URL
                if (string.IsNullOrEmpty(orgname))
                {
                    string url = Request.Url.ToString().ToLower();
                    int start = url.IndexOf("://") + 3;
                    orgname = url.Substring(start, url.IndexOf(".") - start);
                }
            }
            Response.Write(orgname + "<br>");
        }
    
        #endregion
    }
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Mauro    16 年前

    将microsoft.crm.webservices.dll添加到GAC解决了此问题。

    还需要使用以下SQL来确保正在模拟用户:

    Execute as user =@username
    Select * from FilteredActivityPointer;
    revert