Wednesday, 13 May 2015

WCF service binding changes for HTTPS - 404 error


If you are the one who is using WCF services referring from same project evrything works fine until the security feature applied. With HTTPS domain probably all of your service requests fail with 404 error.

If that is the case then create a new binding like below

<binding name="webBinding">
       <security mode="Transport">
       </security>

     </binding>

And add the bindingConfiguration to your service end point.

bindingConfiguration="webBinding"

This will solve the issue.

Happy deployment :)

Sunday, 11 January 2015

AutoComplete extender implementation from client side

AutoComplete extender is one of the way to implement the Auto complete feature to a textbox.

With the below approaches you can get the idea, how can we implement the autocomplete extender differently and different scenarios and functionalities related to the Extender.

The default way of implementation:

<asp:AutoCompleteExtender
                            ID="AutoCompleteExtender1"
                            TargetControlID="uxTxtAddress"
                            runat="server"
                            BehaviorID="AutoCompleteEx"
                            ServiceMethod="GetAddressList"
                            CompletionInterval="1000"
                            MinimumPrefixLength="6"
                            EnableCaching="true"
                            UseContextKey="True"
                            OnClientItemSelected="getSelected">
                        </asp:AutoCompleteExtender>

Alternative way to implement from dynamically from client side using jQuery/javascript:

$create(Sys.Extended.UI.AutoCompleteBehavior, { "delimiterCharacters""""id""AutoCompleteEx""minimumPrefixLength": 6, "serviceMethod""GetAddressList""servicePath""/checkout/payment.aspx""useContextKey"true }, { "itemSelected": getSelected }, null, $get(jQuery("[id$=uxTxtAddress]").attr("id")));

Call this function in document.ready function.

Here we need to pass textbox id, client side selected event and server side service method.

Dispose the behaviour from client-side:

//"AutoCompleteEx" is the behaviour id

if ($find("AutoCompleteEx") != null) {
        $find("AutoCompleteEx").dispose();
    }

Server method:

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetAddressList(string prefixText, int count, string contextKey)
    {
        return AddressUtility.GetAddressesFromService(prefixText);
    }

Client method after selecting the item from the list:

function getSelected(sender, e) {
    alert(e.get_value());//Gets the value of the selected item
}

A way to stop the default Enter button while selecting an item: 

Call the "trapEnter(e)" function from onkeypress event of the textbox.

function trapEnter(e) {
    e = e || window.event;
    var code = e.keyCode || e.which;
    if (code == 13) {
        cancelEvent(e);
        return false;
    } else {
        return true;
    }
}
 
function cancelEvent(e) {
    e = e ? e : window.event;
    if (e.stopPropagation)
        e.stopPropagation();
    if (e.preventDefault)
        e.preventDefault();
    e.cancelBubble = true;
    e.cancel = true;
    e.returnValue = false;
    return false;
}



Wednesday, 19 February 2014

AjaxControlToolkit Unable to load one or more of the requested types

Problem:

While loading the aspx pages from IIS you will get the following error.

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 
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.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.


This is the issue with framework 4.0.

Solution:

Add the following lines to your web.config file.


     
 <system.web>

      <trust level="Full" />

</system.web>

Tuesday, 22 October 2013

Handlers error while accessing sharepoint 2010 dll's in asp.net using C#

This is not an common issue related to handlers. We feel everything is fine and should work as expected.

The main issue with this is within IIS. To access dll's related to Sharepoint 2010 particularly termstore data, we need to change the website to classic mode not integrated mode. This will solve the handlers issue.

Tuesday, 6 August 2013

Consume C++ COM EXE in C# and Invoke methods


The following steps will accomplish the requirement to consume old C++ COM component to consume in C# applications.
Step 1: First create a .net reference dll from the com exe file.
Open visual studio command prompt and run the following command to generate the dll.
tlbimp "c:\Path\xxx.tlb" /out:"c:\Path\xxx.dll"

Once the dll is generated, then add reference that dll to your C# project.

Step 2:
After referencing to invoke any method from the com exe, the following steps can be helpful.
//Get the GUID of com class
Guid clsid = new Guid("Com class GUID");
//Get the type of the com component
Type type = Type.GetTypeFromCLSID(clsid, true);
//Instantiate a new object
object instance = Activator.CreateInstance(type);
//Method name to invoke
string methodName = "MymehodName";
//execute method
type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, instance, strArguments);


That's it :).