.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Thursday, May 25, 2006

HOWTO: Get rid of " Could Not Establish Trust Relationship with Remote Server" error

If you are getting this error " Could Not Establish Trust Relationship with Remote Server" when trying to access a webservice secured by SSL, then read on. One possible issue might be that you do not have a SSL Certificate isssued by a trusted Certification Authority(CA). (Another case of error is explained in this Microsoft Article: http://support.microsoft.com/?scid=kb;en-us;823177). For both these instances workaround given in MS article is a possible solution. It is simple to implement, add this class that implements ICertificatePolicy and add this line of code before you call your web service.

System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();

Code for the class is given below,

using System.Net;
using System.Security.Cryptography.X509Certificates;

public class MyPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint
, X509Certificate certificate
, WebRequest request
, int certificateProblem) {

//Return True to force the certificate to be accepted.
return true;

} // end CheckValidationResult
} // class MyPolicy


You could also check for specific errors/warnings in the CheckValidationResult method, in the above given example, it overrides any error!

Happy coding:)

Tuesday, May 16, 2006

Attention!!! all Infragistics Net Advantage Users

If you are using Infragistics Net Advantage 2005 Vol3, get the latest Hot Fix on this version and apply it now! if you haven't done it yet. This hot fix is out there for a while now, but if you have purchased the product from one of those re-sellers, then the media they sent you do not have any hot fixes. Goto to www.infragistics.com, register your product and get the hot fixes!


This hot fix fixes at least couple of issues I have encountered,

  • Infragistics script library code (js code) going into indefinite loop resulting in your web server going toast! This happens when you are doing add/edits directly into the UltraWebgrid...When this happens your CPU just peaks to 100% all eaten by your iis process

  • Again, Utrawebgrid eating all the memory when it is heirarchial and paging is enabled..(I am not sure about the sequence to re-produce the error!!)



So....Apply the hot fix! and keep coding ;-)

Cheers!

Visual Studio.NET - Web Reference Static v/s Dynamic

Visual Studio makes it very easy to create and consume web services. This note explains how to set up the references to consume a web service with Visual Studio.NET.


In order to start using a web service, you should make a reference to this from Visual Studio,to acheive this,

  • On your VS Solution Explorer, select your project, expand to References,Right click and click on Add Web References

  • Type in URL of your web service and click on Go

  • This will bring up your Web service's wsdl, you can change your web reference name to anything you want and click on Add Reference


Thats it, at this point, Visual Studio does all the work required (like creating your proxy class) and you are set to call your web service's web methods.


Now for some important and interesting observations!


The web reference you just created is a static reference, meaning it is always linked to the web service URL you just typed in. You can verify this by right clicking on your web reference to view the property sheet. You will notice that the URL Behavior is set to "static" with the Web Reference URL pointing to the URL you typed in. This is fine as long as you have only one environment (to TEST,QA,Stage, PRoduction....). But when you have to move your application through various environments in its life cycle, you will need to change this reference and rebuild the application. This leads us to the URL Behavior of "dynamic", when dynamic is set, your refrence.cs file (proxy) will include a property to read the URL from a Config File.


Code will look something like this...



public MyWebReference() {
string urlSetting = System.Configuration.ConfigurationSettings.AppSettings["MyWebRef"];
if ((urlSetting != null)) {
this.Url = string.Concat(urlSetting, "");
}
else {
this.Url = "http://myWS/myWS.asmx";
}
}




Depending on the type of Visual Studion Project your web service client is, it works slightly different,

  • If your app is a web application and making the web reference from your application, this App Setting entry will go into its web.config file

  • If your app is windows application, making a dynamic reference will create an app.config entry and when built will be part of your app.exe.config

  • If you are referencing web service from a Class library project, the entry should be made to the client of that class library, if web project is using this class library then entry should be in web config or if its a win app using the class library, app setting entry will goto app.config!




Happy coding !!


Cheers!

Thursday, May 04, 2006

Response.Redirect not working in server?

[ASP.Net] Have you ever had an instance where your Response.Redirect calls are not working when you moved your code to remote server (every thing worked well in your local machine), first thing you check is your Page's SmartNavigation settings. If you have turned on your SmartNavigation (in v1.1) this might give problems with your Response.Redirect ( Server.Transfer will work ).

As a work around, set your SmartNavigation to false, before calling Response.Redirect

Page.SmartNavigation = false;
Response.Redirect("yourpage.aspx");