Combining CRM WebServices and ASP.NET

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Combining CRM WebServices and ASP.NET

  • Comments 14
  • Likes
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.
Comments
  • What a great idea and what a shame it doesn't work.

  • 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.

  • To Begin:

    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.

    is not true. Any attempt to open an .aspx page in this manner will produce a 404 Error.

  • 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.

  • Your response and admission that the .aspx call directly from Sage CRM is inaccurate speaks well of your character. I have also attempted the redirect option and it also does not work (I'm running 6.2). I wish it would because it would benefit many of us trying to enhance Sage CRM.

  • 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.

  • Thank you. I'm going to read that article as well. I made this process work by redirecting to a server other than the Sage CRM Server. When a .aspx page is in the custompages folder, the result is always a 404 error when the pages is called (FPEs are installed). My Sage Business Partner has confirmed this. It's clear that you and your team are committed because most wind-bag bloggers expect readers to pander to their egos and don't respond to critical feedback. You've responded well and I hope your clarification benefits others as much as it has me.

  • 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.

  • 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?)

  • 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.

  • 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.

  • 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.

  • 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 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,