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 am trying this in SageCrm ver 7.2c. I was able to create a Tab referencing an asp page, which redirects me to .aspx page in Sage CRM 7.2c. I then added Web References for CRM Web Services in .aspx website 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 can see that SID is successfully passed to the ASPX page, which it further uses to get CRM version. It fails at the following line of code saying that - "You are not logged on".

    Source Code line:

    crmService.SessionHeaderValue.sessionId = Request.QueryString.Get("SID");

    getversionstringresult CrmVersion = crmService.getversionstring(); //--- error on this line: "You are not logged on"

    I also checked that web-services are enabled in SageCRM under Administration | System | Web Services.

    Please let me know if I am missing on something.

    Thank You,

  • Hi ksayyah,

    You can generate the code for webservice instead of using web reference using wsdl.exe. I have tried it and it works. :)

    www.codeproject.com/.../Invoking-a-Web-Service-Without-Web-Reference

  • I do not use ASPX page very often. But I do not think that moving a ASPX project from development to production is simply a question of copying the ASPX pages. You would have all the supporting files that provide the configuration. Have you tried creating a new folder under the Sage CRM custom pages folder, and then within Visual Studio opening that as a web site? I think the creating your ASP.NET project under Sage CRM may help. But your issue is not an Sage CRM web services problem.

  • Let me explain in detail what my problem is.

    I've created a tab inside CRM which redirects my ASP page to ASPX page. Initially the ASPX page has no web service reference. I copy the ASPX page and the code behind to "Custom Pages". When I click on the tab, the ASPX page is displayed inside CRM and everything works fine.

    Then I create the web service reference inside visual studio and write some web service code. I can run from visual studio successfully. Again I copy the ASPX page and code behind to "Custom Pages". This time when I click the tab I get the Compile Error shown in my previous comment.. It is apparent that the Web Services reference is not found. Do you know how to resolve this problem? This issue is blocking my work. Any help regarding this issue is highly appreciated.

  • An ASP page can redirect to an ASPX page.

    The ASPX page can reference the Sage CRM web services just like any C# or .NET project can. You will need to make sure that the ASP.NET project has the correct web reference. That job however is not specifically a Sage CRM matter.