Combining CRM WebServices and ASP.NET

2 minute read time.
The links in this article have been corrected and updated.
It might seem that you can't use ASPX pages in the context of Sage CRM, but that is not the case as you can see from the simple example below.



You can create a seperate ASP.NET application and integrate it with Sage CRM, the key point here is that data access is going to be using Web Services.

An ASPX page can be called from a tabgroup or a buttongroup or indeed from an ASP page where the URL has been built using the eWare.URL("mypage.aspx") method. In all these cases the contextual information will be added to the querystring.

This will be in the form of:

?SID=197470424831114 &Key0=1 &Key1=28 &Key2=30 &T=Company

The Value keys are in a predicatable form, and the nature of the keys is discussed here:

https://community.sagecrm.com/blogs/hints_tips_and_tricks/archive/2007/07/13/key-values-in-urls.aspx

The most important of the variable name/value pairs that is included in the querystring is the SID. The SID is the session id. This should be valid whether used in ASP pages, the system pages or a webservice interaction.

There is an example of using the SID from an existing system logon here:

https://community.sagecrm.com/blogs/hints_tips_and_tricks/archive/2007/10/24/sid-and-key-grabber.aspx

The above ASPX example was a simple little project. The fields have been added to the form as below:



Once the Web Reference to the CRM Web Services has been added to the project the code that allowed me to add the company details using the Web Service API looked like this:



Code:



myCRM.SessionHeaderValue = new SessionHeader();
myCRM.SessionHeaderValue.sessionId = Request.QueryString.Get("SID");
getversionstringresult CRMVersion = myCRM.getversionstring();
//Response.Write(CRMVersion.versionstring);

String strCompanyID = Request.QueryString.Get("key1");
queryentityresult CompanyQueryResult = myCRM.queryentity(int.Parse(strCompanyID), "Company");
ewarebase CRMBase;
CRMBase = CompanyQueryResult.records;
company myCompanyRecord = (company)CRMBase;

CompanyNameData.Text = myCompanyRecord.name;
COMPSLADATA.Text = myCompanyRecord.slaid;
CompWebSiteData.Text = myCompanyRecord.website;
CompTypeData.Text = myCompanyRecord.type;



Note

In pages called from the tabgroup "User" in the My CRM area look like:

?SID=197470424831114 &Key0=4 &Key4=4 &T=User

Key4 here represents the Current Logged on user id. For example to be able to retrieve information from the UserContacts table then you would have to make sure that the table was exposed in Web Services.

For existing tables that you want to expose via the WSDL file then you will need to change the flag (bord_webservicetable) in the custom_tables meta data table. This can only be done in SQL. UserContacts is not exposed to webservices by default.

Within the SageCRM .NET API then the UserContacts table can be interacted with just like any other table.

And finally

If you are working with ASP.NET pages using this technique then be aware that if you invoke the Logout method it will log off your main CRM session as well.

  • I was able to create a tab referencing an asp page which redirects me to .aspx page in Sage CRM 7.2. I then added Web References for CRM Web Services in .aspx project in visual studio. I'm able to access CRM Web Services when I run my program in Visual Studio.

    However, when I access the page through the tab in CRM, I have reference issues which I'm not sure how to resolve.

    Following is the error I get. Note that in the C# codebehind I have "using LifeAlerWebService.CRws" which cannot be resolved.

    Server Error in '/CRM' Application.

    --------------------------------------------------------------------------------

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0234: The type or namespace name 'CRMws' does not exist in the namespace 'LifeAlertWebService' (are you missing an assembly reference?)

    Source Error:

    [No relevant source lines]

    Source File: Line: 0

    Show Detailed Compiler Output:

    c:\program files (x86)\sage\crm\crm\wwwroot\themes\img\default\Icons> "C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\Windows\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /out:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\crm\66cb2578\e1e85770\App_Web_lifealertwebservice.aspx.f61bff87.in2irz-v.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701 "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\crm\66cb2578\e1e85770\App_Web_lifealertwebservice.aspx.f61bff87.in2irz-v.0.cs" "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\crm\66cb2578\e1e85770\App_Web_lifealertwebservice.aspx.f61bff87.in2irz-v.1.cs" "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\crm\66cb2578\e1e85770\App_Web_lifealertwebservice.aspx.f61bff87.in2irz-v.2.cs"

    Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.4927

    for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727

    Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

    c:\Program Files (x86)\Sage\CRM\CRM\WWWRoot\CustomPages\LifeAlertWebService.aspx.cs(6,27): error CS0234: The type or namespace name 'CRMws' does not exist in the namespace 'LifeAlertWebService' (are you missing an assembly reference?)

  • Thanks for letting me know that you have got this to work for you. It is very difficult to anticipate all the other filters and extensions that maybe installed on a web server and Frontpage is something that I never have installed on my machine so I don't think I would have seen your issue. I'm glad that you have the support of your Business Partner in your investigations. They should be a big help in understanding how Sage CRM's APIs can be used in your local environment.

    If you have have other questions about the capabilities of Sage CRM, especially as you investigate the web services, then an excellent source of help are the Community forums. There is usually a very prompt answer to questions that get posted there and you are drawing on a very wide pool of expertise.

  • Hello

    We do try and make sure that the articles that we write are as clear and accurate as possible. I this case I am pretty sure that everything that I originally wrote is correct although I may have failed to state all of my assumptions. I hope that I have added further information on how you can mix SOAP Web Services with ASPX pages.

    The entire team at Sage is keen that you should be able to enhance Sage CRM in the way that is particular to business requirements. community.sagecrm.com/.../redirecting-to-an-aspx-asp-net-page-from-a-classic-com-asp-page.aspx

    I've added another short article that shows how to redirect from a classic ASP page to an ASPX page and the information that is available within the QueryString including the Session ID. That session ID and the contextual information can then be used by SOAP calls within your ASPX pages.

  • Hello

    I've just tried this. The ASPX page has to be placed under the custompages folder of the install of Sage CRM. I created a test page called testaspx.aspx that contained a 'Hello World' message. I saved the file under

    C:\Program Files\Sage\CRM\CRM70\WWWRoot\CustomPages\testaspx.aspx

    I could then call the file via the tabgroup and by a redirect from a classic ASP page.

  • I'm not sure what you mean by "doesn't work". You most certainly can reference the Sage CRM Web Services in ASP.Net pages. And you can pass the current session id from the User Interface to allow you to use with the Web Service.