2011年7月20日

[ASP.Net]Compiler executable file csc.exe could not be found.

Got this error while browsing web site.

Obviously this error occurs due to compiler not found, so either check if corresponding .Net framework has correctly installed on the machine, or modify your web.config to use specified compiler version.

<providerOption name="CompilerVersion" value="v3.5"/>

Just change v3.5 to corresponding version.

2011年7月19日

[WCF] Enable WCF Windows Authentication

This is a very quick note on how to enable WCF windows authentication.

Well it’s simply enough but somehow I ran into some errors like [Authentication schema mismatch between server & client] or [base address prefix not match] (not really remember the actual messages, but should be close)

This article describe the steps clearly, only one thing to remember – don’t forget to enable metadata exchange endpoint, and if you did so but the error still occurs. try remove mex endpoint and enable httpGet in service behavior meta exhange section then point service behavior configuration to that section instead.

example configuration is like bellow:

   1: <system.serviceModel>



   2:     <bindings>



   3:       <basicHttpBinding>



   4:         <binding name="basicHttpBinding" allowCookies="true" bypassProxyOnLocal="true">



   5:           <security mode="TransportCredentialOnly">



   6:             <transport clientCredentialType="Windows" />



   7:           </security>



   8:         </binding>



   9:       </basicHttpBinding>



  10:       



  11:     </bindings>



  12:     



  13:     <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true">



  14:       



  15:     </serviceHostingEnvironment>



  16:     <services>



  17:       <service behaviorConfiguration="serviceDefaultBehavior" name="Services.UserProfileService">



  18:         <endpoint address="" behaviorConfiguration="basicHttp_Behavior"



  19:           binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"



  20:           name="userProfileService" contract="Services.IUserProfileService">



  21:           <identity>



  22:             <dns value="localhost" />



  23:           </identity>



  24:         </endpoint>



  25:       </service>



  26:       



  27:     </services>



  28:     <behaviors>



  29:       



  30:       <serviceBehaviors>



  31:         <behavior name="serviceDefaultBehavior">



  32:           <serviceDebug includeExceptionDetailInFaults="true" />



  33:           <serviceMetadata httpGetEnabled="true" />



  34:         </behavior>



  35:       </serviceBehaviors>



  36:     </behaviors>



  37:   </system.serviceModel>


2011年7月14日

[EF4] Loading related objects explicitly

In EF4, we can set LazyLoadingEnabled to true to enable lazy loading feature, which, allows us to access database only when related database object (i.e, detail tables) are explicitly accessed in code.

This creates pros & cons. but if we do not pay much attention to it, it could make too much connections to the database then we expected and leads to database performance issues.

There’re several topic we need to consider to choose if we want lazy loading or eager loading, here’s a good MSDN article to help us to make our decision, also with useful code examples.

The following codes are a note on how to explicitly load related objects with one query.

        protected MASTER_TABLE[] QueryApplyFormDataRelated(Func<MASTER_TABLE, bool> where) {
            using (var db = new DBEntities()) {
                using (TransactionScope scope = new TransactionScope(
                                                                        TransactionScopeOption.Required,
                                                                        new TransactionOptions {
                                                                            IsolationLevel = IsolationLevel.ReadUncommitted,
                                                                            Timeout = TimeSpan.FromSeconds(10)
                                                                        })) {
                    db.ContextOptions.LazyLoadingEnabled = false;
                    var table = db.MASTER_TABLE.Include("EMPLOYEE_DETAIL.SALARY_DATA").Include("VENDOR_DETAIL.PAYMET_DATA").Where(where);
                    return table.ToArray();
                }
            }
        }

About Me