tag:blogger.com,1999:blog-73166968472984002322024-03-05T18:21:10.678-08:00Imran's Knowledge Base WorldInformation Sharing, Technical Articles. You can find solutions, best precticies for ASP.net application. More knowledge sharing on C#, AJAX, SQL, .Net Framework, OOPs Concepts, SQL Server 2005, SQL Server 2000, Programming.Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.comBlogger165125tag:blogger.com,1999:blog-7316696847298400232.post-55446461710712946842022-10-13T03:57:00.000-07:002022-10-13T03:57:04.059-07:00Exposing child class in Swagger documentation<p>Hello All,</p>
<p>
Writing this post after a long time, will make sure to keep continue sharing
my knowledge
</p>
<p><b>Problem Statement:</b> </p>
<p>Need to expose inherited / child class into Swagger documentation</p>
<p><b>Use case:</b></p>
<p>
This is very common issue, where you have multiple inheritance classes in your
MVC application. And you need to expose all your child classes into Swagger
documentation to make sure Solution/System Integrator should have visibility
to use all possible cases based on their requirement.
</p>
<p><b>Solution:</b></p>
<p>
In WCF we have to decorate class by adding <span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">KnownType</span> attribute to all your child class. In latest version of swagger new
decoration has been added which is <span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">SwaggerSubTypes</span>.
</p>
<p>
You have to decorate your all child class with <span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">SwaggerSubTypes</span> attribute, this accepts array of types to expose all your child classes
</p>
<p>
Consider you have one base class <span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">Computer</span> and two inherited classes <span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">Laptop</span> and <span face="SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace" style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">Desktop</span>. You have exposed API to create new peripherals
</p>
<p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs2UZicSdnc0tLIYihyKYcb7uMTbyz8CO5X52UJW8MFktTCPpYAGE114QpLTW3ZFYIgGWEsWCnld--ctEcwzUG4YYraxE7HhOfmZLdl_gHG3Q2W6TbEm7-VAdM3DSYqSFPtMef3Ff_7o2C6Yt3jxp3Wmf2qaO0Ilss3EsRFx5YtFwRra8dneoSiCXE/s628/One.png"><img alt="image" border="1px red solid" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs2UZicSdnc0tLIYihyKYcb7uMTbyz8CO5X52UJW8MFktTCPpYAGE114QpLTW3ZFYIgGWEsWCnld--ctEcwzUG4YYraxE7HhOfmZLdl_gHG3Q2W6TbEm7-VAdM3DSYqSFPtMef3Ff_7o2C6Yt3jxp3Wmf2qaO0Ilss3EsRFx5YtFwRra8dneoSiCXE/w441-h261/One.png" title="Create peripherals" /></a>
</p>
<p>
So base class have two properties, we will create two new base class to create
inheritance
</p>
<p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGLcSx5pBMRK0B9LkXoUUFu49JwMnNM7mz1pcYDo62D36w_BD37R6bfcIvN3WCUaJEumR2oV8RsRWpLgadnPNAPAlyslXwo4VBYDfn7TVs9I5g2eKeE_1BzqKvCFflUP7g3STFGVYV3yjyHC9PmO4LV3zX8c0QpFxsQxorYDrKVZVPg8CcNeyrzIy9/s591/Two.png"><img alt="image" border="1px red solid" height="261" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGLcSx5pBMRK0B9LkXoUUFu49JwMnNM7mz1pcYDo62D36w_BD37R6bfcIvN3WCUaJEumR2oV8RsRWpLgadnPNAPAlyslXwo4VBYDfn7TVs9I5g2eKeE_1BzqKvCFflUP7g3STFGVYV3yjyHC9PmO4LV3zX8c0QpFxsQxorYDrKVZVPg8CcNeyrzIy9/s591/Two.png" title="Class tree" width="441" /></a>
</p>
Our goal is to expose all three object definition in Swagger, so for that lets
add decoration to these classes
<div>
<p>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkxMEA_LgE35dHX9CbBL_RQfr2YyNzMlD_6Z53RfYMlpFcPmocfuyS4BCZEppq2XYGz3k5EM2rwvQz5lemVEI3CQVTJBrQyWg3wdyIxKsUW_1DJzZzl87PAb7KuhGV-Yhd9xOmqldk4eizpW9SpDd631ilEx1MTfEuoxU1O5vPwZRv9ikoolJflYDQ/s785/Three.png"><img alt="image" border="1px red solid" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkxMEA_LgE35dHX9CbBL_RQfr2YyNzMlD_6Z53RfYMlpFcPmocfuyS4BCZEppq2XYGz3k5EM2rwvQz5lemVEI3CQVTJBrQyWg3wdyIxKsUW_1DJzZzl87PAb7KuhGV-Yhd9xOmqldk4eizpW9SpDd631ilEx1MTfEuoxU1O5vPwZRv9ikoolJflYDQ/w565-h453/Three.png" title="Expose three classes" /></a>
</p>
<p>If you want to hide Computer then mark it as abstract. </p>
<p>
For this to get working in your code, you need to add few lines in <span style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">Startup.cs</span> file, copy below lines into <span style="background-color: #f2f2f2; color: #006881; font-size: 14px; white-space: pre;">ConfigureServices</span> function</p>
<div id="box">
<pre class="csharpcode"> services.AddSwaggerGen(c =>
{
c.EnableAnnotations(enableSubTypeAnnotations: true);
});</pre>
</div>
<p>You are done!</p>
</div>
Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-90210041504506458492013-11-27T23:40:00.000-08:002013-11-28T00:51:03.185-08:00Exposing property as OperationContract in WCF<p>Hello All,</p> <p>I would like to share thing which I just learn today J</p> <p>In WCF usually we work with operation contract i.e. methods. I was trying to expose property not a method. I found solution and here is the way it should be</p> <p>Simple Service Contract</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYTMvMQFaVPSiCdxLu-nC4UiLz_6zXAn3mpS6KLX0Sdr7n5mfG4AFWASpDGVWiJ800QGCr5F97u42YUjGxcBYdm1OgjLd9WZlosseA7sq1-9kxmVyHcigpRwVjiKEoSMcJnQ9_4FrI_T4/s1600-h/clip_image001%25255B10%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image001" border="0" alt="clip_image001" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-uQAU67cTxmcFmFXBjCpgdH0jioIvcIz7jYArOOzYLm6ZyFTDLA_H7mQmwufzh3FPsF2WyzwH76GQZFOXMX7bMPSZCps6rGPS57cMBxALPuKuWi597tulQ7hUvTAu0yFWKTQ8lKTGfK0/?imgmax=800" width="370" height="195" /></a></p> <p>Contract Implementation</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdSaw7tm6qdsGPv-Fe1-pVyMwYldgwxSbKZAm34yYNWTp3LzERstfVW4BYp7SMuG7JrMABBI85n2F2RdihbIP2eIvRVyxHb5uFdnQ_efAtOin18Qf7VEnfz1VCvv1T18b7xBQx0VQBUO8/s1600-h/clip_image002%25255B4%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh43IN-MndnRTLpxYMOM9amJuao08HEhcqWfU05QXYcOx8Pel5yb4w0zZjc50WpoVEWBb_xgw6I75YPEbbZniNw4bTZUBPDOp5-tE72rx5hjrc_AFkWYVOxOllz7tZLhDmoV9XkgGxJD4M/?imgmax=800" width="630" height="148" /></a></p> <p>Nothing fancy, and here is client to call this service and its output</p> <p><a href="http://lh5.ggpht.com/-RVKJ4w-8gqc/UpbzqXXVNUI/AAAAAAAAAvM/ybQu0G5V7Vk/s1600-h/clip_image003%25255B5%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image003" border="0" alt="clip_image003" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi037Xt-U_WDiKdC6j5knQmMRTI7ugIXhJEl5z9ouTodG7EOWf5QXXKAc4Qz8TIofN2J7JAST56y0QadKfpfmB_Zvt_5GQz5za5YbTrvL14dpXiYwJjIPz5FDamqBRkCl3iygQVErjJU4A/?imgmax=800" width="533" height="201" /></a></p> <p>So before we go further, I would like to make you clear about what we are going to do.. So requirement is I don’t want to change DoWork signature, but still want to add some additional information which DoWork should use if available, means a kind of optional parameter I would like to add. </p> <p>For that I need to add property and get it exposed into client. So my new service contract will something similar as bellow</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijQhV5sMEJPx8q1C9G-n2oxsTidOe0-NcHiz1UFbSS7OfFkVwswqwOjpiMTwwc_IufICoxW6ss47xAAtPPHlOGFn8AiYldCeeYcDv0ddqk1g_s4o4cQNTd5TGgPAwC7bW2_Q_zLeMAlsc/s1600-h/clip_image004%25255B5%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image004" border="0" alt="clip_image004" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwxQI9ExGoFgDGOmKQBt2z12uNI99dVIFSjT-6C-IMCyZuXWHfY4P1yfnorww5-a8M7eHyA4Gt911woPsfXQo5PzHOMV85ylkSDZiG6mmCzsJb1M-zYNKu5bwQm9hyCuy_DD_EpBl72H8/?imgmax=800" width="275" height="278" /></a></p> <p>You can see, one new property Message added with only set, as I want to be as one-way. To Expose property you have to write <b>OperationContract</b> attribute ot get or set not on top of member just we do with method.</p> <p>Now change little bit in logic to use Message if it’s there if not then behave normally.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS5msQOLe4nduWhaTgbI87b3lzfywE2C2iOBtFYn3Do3TAjH847zcD-EMf_4L6yLR3y2B3fBcnZ1WRLeVxQzIpzUgzqGUp5U0Obny3GpDjSZBlwY4X2HNDpQMfSpYo1WWeL4E6-InfBAM/s1600-h/clip_image005%25255B5%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image005" border="0" alt="clip_image005" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5HwlxPWoqrsx6GozwrSjQ4PiGflAzfhCapUIzSKQq8Mo858OGX5mRTcR_DrDv-suQoQur-LSx5iweOHXOFv5wzRRkwA0pQW6H2kEQW1ZbvSExa6iqVw1lhKuif1PQaJEPeq8EHJ3u0WU/?imgmax=800" width="502" height="213" /></a></p> <p>After updating reference, I can see WCF internally convert my Message property into method by adding <i>set_</i> prefix.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7cHjZPBnNvJz5GhySGNHvOFoDf_p-4lVRp7fZdAugPsFCMXgLANMYMnd_bEf09PuUhTvCaMGWpNvexIbr8fwqd-Wjrsb9vHROYd-qSJf-aCK09o9OIUvtRMEQ1PFHC-D_AIrb7B4Ba7c/s1600-h/clip_image006%25255B7%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image006" border="0" alt="clip_image006" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPHn2w09UlpPD30G4hiTjRNQw8aXajITJVO8aNAVa5g1QV2uf_0gyZqxktGnNEHhMvW7J47paqJGaBm9UrdfePonEo65Bv_gtMZhfMrGL4ctkTbTfQzvW7vDa8oKeNcDlIUUQqMtSgcE8/?imgmax=800" width="508" height="249" /></a></p> <p>Let’s set message and will call my work method again.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmSCHj9v_KT_9F7aa1tLWvNOM1ZniVauDdGKVRWHRtAL1KpamK8iWAOXVYIZGtCGRM_vayrsgmMTOOyvCw-AuWUVlB2NlRGIlKF7OlTujl-VogG4-vBoXCe3-0aI5PdqT6yuvV4p60O0U/s1600-h/clip_image007%25255B6%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image007" border="0" alt="clip_image007" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjCHVFxCOd1Q7ogFtlS6zwgF19bqxEXikE58j4o76FsWoZNF3KQHGPlc6p_0B9ID1XSegjmWfEWpB9ka-QYRjI7iLwbED115bxmhKuLNKKGCSwnUjnz9C71Mr5uHZ1TuA_Icgboxwtylk/?imgmax=800" width="512" height="211" /></a></p> <p>Demm it, doesn’t work! It’s fairly simple and straightforward!!! Where is the issue? @#$%$@@#$</p> <p>In debug I can see message is set property to my private variable… </p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNh3i_ozZjChprjqFOS4PrpjUnwJCzdU67T-QwyCDN7KS0i4DGFKpIZ_r9Tf0GEI65lAKLUn48e0CKMTgzWj_7avJS4TUCmYLKkUteOEBCBfnRKB3EWnyadluYQ8lEQpirAY9V9K1aZmE/s1600-h/clip_image008%25255B4%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image008" border="0" alt="clip_image008" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQBijl5CSerDxS2JjbusrZlLkuJNhxotLA665tDtncDmxwKuoJbUF0avxLkvolJb8Ei2HWBJJOFsfg980ssHeeYws9YZtI36qzsSfx3r1sSuxwtu3rlOSR96UONs6Qugh3KWmjV94MiF4/?imgmax=800" width="511" height="162" /></a></p> <p>but when I call <i>DoWork</i> I don’t see value is persist!</p> <p><a href="http://lh5.ggpht.com/-xapVOcr7UBs/Upbz7u-Y18I/AAAAAAAAAws/g5fkuB3meVg/s1600-h/clip_image009%25255B5%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image009" border="0" alt="clip_image009" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5-fk8MvXBVjSIVU9EyNHVqjxKF6Td0XWdo73UtbUWllDhgWXRheKJtYvDf1Ic65lSGWIU_ruciFayCZgLXIT1GALtA4XNpglNTzmp2pdUlLwZjbaSAkCxloweHewUEvegX6xvkkJTpmU/?imgmax=800" width="516" height="272" /></a></p> <p>Its WCF setting that we are missing, WCF by default does not keep context for ever… we have to tell them to keep it alive <i>per session</i>, <i>per call</i> (default) or <i>single</i>. Per session requires some more extra efforts to get it working… let’s keep simple by using Single, it’s part of service behavior, lets add and see if that works…</p> <p>Add attribute…</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3jvFFOVA6mqTGQgk_8yaVNcPtmLvTsJ56AswRhlC5ZLpQrOUghzelubCnOlaQlhdaD5AGBXeEhLgUT8RlTE6HRWnuByVpOYb2zmV-Nd2o1DAyWL9f7dw4zylsu3vaq8I1QkMJTnEnusg/s1600-h/clip_image010%25255B5%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image010" border="0" alt="clip_image010" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhF-bvOfCtgJiogsDZDccXotFlsTREyf9l0EnRrqKqSustPY8r6ymJtTLAhseVEJp09_thXposSqvL0l7RDPiaOS3sXIuhuOPpS-VZ9z79OxdcU09zx9JfXtQukTePnSgqCHV5koTB9PCw/?imgmax=800" width="522" height="257" /></a></p> <p>And let’s make call from client again..</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq_y9khBqNp6ozrJ6q5gcdjVlppjmK92m0x8bAXPKkxOSt71JWHtmPuVc_quxlruQRfDu7QXqXNY0LLgGdLpb8vxUY9aV0RSlO0tQvhi9v8A3OkAo_ofSnaXeZHgbr0yAYZLEoO09nbmQ/s1600-h/clip_image011%25255B5%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image011" border="0" alt="clip_image011" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzLg0qt84v-7DzNJvpuwBxKef0iNKv8aHzi1E3z-kg1cA1rJMcNzlLm524kvUFxevMnLj6PASvB01WizYQGjhMDMLSI2A06_aMBNicwiGvUKMU0kmk0mnrNrBKNyI9JNNd5sHw7u3pPPE/?imgmax=800" width="525" height="218" /></a></p> <p>Yes… we got it working J now as we make context mode to single, subsequent call of DoWork will return same result. That means its consider as a kind of Static</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH-g1dXNnJWvyyHCuc-ZS4mEt3zMT697vz46d-Z7pGGo-3ZVMtDAetKN6PLDj2iAAWT1i01HBAhZnwqdHttMhKm7JLkVlb5ZX41qkzfy-Re7ioc237xvps8IgJz76iFTLGExMrOHmRF2k/s1600-h/clip_image012%25255B4%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image012" border="0" alt="clip_image012" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgunxZp8OKNJOR17lOx-eSTqPVHaL5n8Rc2EqXoyTvep1QFdNwBXk5ly-szoIJ7e0-454J7qmzEQk1d7GWc5RDmVMdfILY-hiiE-F__anzsz8Du8RZ5vxuHSmtBVp2dvWU_eKlL1lkJG2A/?imgmax=800" width="530" height="211" /></a></p> <p>If we switch context mode to session then following code will behaves as expected</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi65xvJfJ7trmL-CIUoWZIPE7FoIUjRPut0iFzKU1QI21Poe7CLyD-SMhne6d0Mim095dEGBxxkbPvpzJsXX2uRpjXkmJhCxpQLd1YQ00WGM66JdsO28FqmjLFyHHBk4wfwVTy-BioHVcE/s1600-h/clip_image013%25255B7%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image013" border="0" alt="clip_image013" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho9Tf1Jo4AvntWirvgTnNqawykBZbKufb79qC3X4f43gPJAXGu0HZJPiPk6Y7c0_dVq7kpzfD9vJRfDgQD6NXZS5NC5dwnkVm6qIVpnApiiIegl6dgtXULCiUVf4n6vRQtv65lVDYRw-Y/?imgmax=800" width="530" height="339" /></a></p> <p>Hope this helps.</p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com2tag:blogger.com,1999:blog-7316696847298400232.post-23858534821619526222013-03-08T05:32:00.001-08:002013-03-08T05:32:09.086-08:00Understand the behavior of .NET function Math.Round<p>Hello All,</p> <p>Recently I faced wired issue with <span class="keyword">Math.Round</span> function. What is assumption for <span class="keyword">Math.Round</span> function is “Rounds a double-precision floating-point value to the nearest integral value”</p> <p>Lets examine this case. We are trying to Round 10.5 and 11.5</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXn9g52YDAYlrhBGLCjOcBwte_gzVlE-M1leNnkAIYVwLRzApJ7DYMUHNAabg-zGf6hHBStHphW1Y-UxrPD_Cuhqs4PgV6kXhWEL7GtrF0K39yIzWbggIpwlmRJv9O7InWdim-KOjTXyM/s1600-h/image%25255B2%25255D.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgagAWyVSAc_nvvgHRc_ZQnTE60yUE8XjYFcTWYJKcV78-VicB27j9YicBnX8hAESR4mUZVns_H0wzKaTrtQIAJMDUHRbpEPjAQqZGv7Z_SHdPTVLWwdrMhDubZdgJlNfAEXFXabYot2jI/?imgmax=800" width="353" height="93" /></a></p> <p>We are expecting result as 11 and 12. Let’s see the output</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfIsyYyOxV1t_EA8PuyqNQP_C7ocGwqTfDVkEfiJJSswejrkn8daHL_a8S_8RAulpz_h-PClo1q8uNRrOgbjuAlF1F581qy9mWWInXRp6KDYe5EocxCgQws1KRssycVBQQEXWYbPRe_Qk/s1600-h/image%25255B13%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizSnzqYFTlVjZSpz7ZUNkiGmWlZguUffLdvxmV1Yb17weWCORWFoYSZDYVR4BST9Xoy_4q3tOSrbJLqczuZ-sZIZNSNctsxL_BAelkNs2ujrmsawODD1A0aTJsftudZ2wOGB2NhfPVKjE/?imgmax=800" width="167" height="97" /></a></p> <p>Unexpected!!! Does this means <span class="keyword">Math.Round</span> having bug? Well the obvious answer is No. There is no bug in <span class="keyword">Math.Round</span> function. Basically we are not using <span class="keyword">Math.Round</span> function properly <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW48mFskfZ9-wP49t8Emuq1gpKMD0bjg7TOdoR5_TCAqyEpNCelN3iAUthvpsXPFrF4dnAwJi1RPMAfIz3rP5mzV_cn6DRENJSoqqd4scpY297XsBZwaM-IVEjLESYL-C9VIIz6Xt2z5E/?imgmax=800" /></p> <p>Let’s check what documentation say about <span class="keyword">Math.Round</span> function.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEtHURZ8HrqFad8-gSJQ8lA2c2YnQztH74zTklDu_dcWynMkSckNuenCNl0bngqcvXbUe5gcaABAdZOkNrX7j663aaljmkORgkTKVpXAG0XyVSbuUijkwHZ8I-cxLUP-hfJuWk8FvIAu8/s1600-h/image%25255B14%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvaqvIPvcqKSgXS3YB8HRyiD54NekEcPSas5fbiuWnFplLpPvVo8hlTDd8CH-jcGzqjToCc6wavIcmdvIvuWwSD0D-BJ7TdTybgeQ7OK4jP0343B6PGlFIMfwGEcbtTv4ajV2Kyb9ents/?imgmax=800" width="660" height="247" /></a></p> <p>The document says, it will return the nearest EVEN number is returns. This is a reason why we got 10 instead of 11.</p> <p>This is default behavior of <span class="keyword">Math.Round</span> to return nearest even number, however we can change the behavior to get out expected result. There are few overloads provided by framework, we can use one which have control to return nearest even or odd which always be larger, in our case we always need large one. So lets use overload function of <span class="keyword">Math.Round</span></p> <p><a href="http://lh6.ggpht.com/-UdmndXRs870/UTnoS0hxD9I/AAAAAAAAAtw/adx9Wj7nWbc/s1600-h/image%25255B17%25255D.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXJifhmUYMpVRHS6NERiDqkXsvfmr8oNv18iZQ6-4CKE0DJ32zeprMnk2TkqgoeoLPSeUUNokRFaXFaPrSyk1-8OElGlNcqSzVkoH-z7gr7kdP5HLjyPTEmiuOGFNPP5ZcLneSN-TUcGY/?imgmax=800" width="537" height="85" /></a></p> <p>We are mentioning to give us a number which is away from Zero mean bigger one. This will give output as we are expecting.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh__btS-65UIScUSvGom7dKgTduQH77gWAnrPLarnmYPXz43p7BVklhEhGlRK39yBholF5d07gohNrH1MgTrOs2JifqRtfJWA0syi3Hefdymo0cZD1zDXx5jSZHlWZD6LGh-NBljXCsOPg/s1600-h/image%25255B20%25255D.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSY_faSRzIAW_m8jbO5Hy4Iqyavpx1Nfq0y_hhl50TctKe0OyFATDCDtLTAkn9CAG6GyGFSYyVsqIRDB9EQndu0jsUVMYH2mIIb2hxVKIQl7XwM6-PL9IekGU6iLDP0TQCw6cQBtQ6h9E/?imgmax=800" width="166" height="96" /></a> </p> <p>There we go. So best practice to use <span class="keyword">Math.Round</span> is always call overloads which is taking mode as an argument. There is two option for <span class="keyword">MidPointRounding</span> enum, one is <span class="keyword">AwayFromZero</span> and another is <span class="keyword">ToEven</span></p> <p>I am sure lots of people is going to change their code after reading this blog post <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW48mFskfZ9-wP49t8Emuq1gpKMD0bjg7TOdoR5_TCAqyEpNCelN3iAUthvpsXPFrF4dnAwJi1RPMAfIz3rP5mzV_cn6DRENJSoqqd4scpY297XsBZwaM-IVEjLESYL-C9VIIz6Xt2z5E/?imgmax=800" /></p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com3tag:blogger.com,1999:blog-7316696847298400232.post-75399235608164054992012-12-10T02:28:00.001-08:002012-12-10T02:39:48.440-08:00Query to Find First and Last Day of Previous, Current and Next Month - SQL Server<p>Hello All,</p> <p>This is normal requirement to find First and Last day of Month. I got one in which I have to find not only current month or given month but Previous and Next month as well.</p> <p>Following query will gives start date and end date for previous, current and next month respectively. That is First Day of Previous Month, Last Day of Previous Month, First Day of Current Month, Last Day of Current Month, First Day of Next Month and Last Day of Next Month.</p> <div id="box"><pre class="csharpcode"><span class="kwrd">DECLARE</span> @PreviousMonthFirstDay DATETIME<br /><span class="kwrd">DECLARE</span> @PreviousMonthLastDay DATETIME<br /><span class="kwrd">DECLARE</span> @CurrentMonthFirstDay DATETIME<br /><span class="kwrd">DECLARE</span> @CurrentMonthLastDay DATETIME<br /><span class="kwrd">DECLARE</span> @NextMonthFirstDay DATETIME<br /><span class="kwrd">DECLARE</span> @NextMonthLastDay DATETIME<br /><br /><span class="kwrd">DECLARE</span> @CurrentDate <span class="kwrd">AS</span> DATETIME = <span class="kwrd">CONVERT</span>( DATETIME, <span class="kwrd">CONVERT</span>( <span class="kwrd">DATE</span>, GetDate() ) )<br /><br /><span class="kwrd">SELECT</span> @CurrentMonthFirstDay = DATEADD(dd, -(<span class="kwrd">DAY</span>(@CurrentDAte)) + 1, @CurrentDate)<br /><span class="kwrd">SELECT</span> @CurrentMonthLastDay = DATEADD(d, -1, DATEADD(mm, 1, @CurrentMonthFirstDay))<br /><br /><span class="kwrd">SELECT</span> @PreviousMonthFirstDay = DATEADD(m, -1, @CurrentMonthFirstDay)<br /><span class="kwrd">SELECT</span> @PreviousMonthLastDay = DATEADD(d, -1, @CurrentMonthFirstDay)<br /><br /><span class="kwrd">SELECT</span> @NextMonthFirstDay = DATEADD(d, 1, @CurrentMonthLastDay)<br /><span class="kwrd">SELECT</span> @NextMonthLastDay = DATEADD(d, -1, DATEADD(mm, 1, @NextMonthFirstDay))<br /><br /><span class="kwrd">SELECT</span> <br /> @PreviousMonthFirstDay PreviousMonthFirstDay<br /> ,@PreviousMonthLastDay PreviousMonthLastDay<br /> ,@CurrentMonthFirstDay CurrentMonthFirstDay<br /> ,@CurrentMonthLastDay CurrentMonthLastDay<br /> ,@NextMonthFirstDay NextMonthFirstDay<br /> ,@NextMonthLastDay NextMonthLastDay </pre></div><p>Output as of 12-Dec-2012<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-9z9TKYGFgpw8MYjku6DZlCtHrbd_LAAulhvNS75k-ulAIsqCIQxNQdtHPUn1PGHH0lGrh8egsIRBMLOpCzoPwJ9W-w0T-BTD-Ir6HuT7a4qUvSzCDm1-B68bIn0_ZulTzqK2VpD3tMs/?imgmax=800"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNrShePgi3pH7W5fWBJaST_F7Vm-CxqVDa-C2Jl6OLVzasn77PbfVrVEzkyNOlmQV9-ORYZgwZsIY950MEhyidev6Zru6AVuy9Ca3yMpzweVDhDEf5xbXn_VVgcwUgGz4gIx3doXKNU-I/?imgmax=800" width="660" height="85" /></a><br />You can make this more generic by replacing <span class="keyword">GetDate()</span> with perticular date while setting up value of <span class="keyword">@CurrentDate</span></p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-70845157833619543312012-09-20T23:16:00.000-07:002012-09-20T23:23:28.329-07:00Operation is not valid due to the current state of the object<p>Hello All,</p> <p>While working with web application, there may be case we got ‘<strong><font color="#ff0000">Operation is not valid due to the current state of the object error</font></strong>’ or ‘<strong><font color="#ff0000">The URL-encoded form data is not valid</font></strong>’ while doing postback</p> <p>There may be other reason but one of the reason is form collection reaches its limit of maximum number of keys that it can hold a time. Means you have huge amount of data and you are trying to postback that data to server which end up with this error</p> <p>‘<em>Operation is not valid due to the current state of the object error</em>’ or ‘<em>The URL-encoded form data is not valid</em>’</p> <p>Microsoft has added this as security for Form can have 1000 items at a time, however thanks Microsoft also provides way to change this <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQd4OC7NhHQOBIHRp2u0EAns6CSB3Wl8UMljDxG-C537JY0ChGvUi4ZARyj7ppah4Dlqm5xcSzvhzmTxG79_XyrsWG58McujgVeYcf-hcyFAMxkDZkz0Yoba8gATDlwTf8LUpLO4JXBMQ/?imgmax=800" /></p> <p>To change this add following setting into your configuration file</p> <div id="box"><pre class="csharpcode"><span class="kwrd"><</span><span class="html">appSettings</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">="aspnet:MaxHttpCollectionKeys"</span> <span class="attr">value</span><span class="kwrd">="10000"</span> <span class="kwrd">/></span> <br /><span class="kwrd"></</span><span class="html">appSettings</span><span class="kwrd">></span></pre><br /></div><p>In case you have issue with Jason data then you have to add following settings</p><div id="box"><pre class="csharpcode"><span class="kwrd"><</span><span class="html">appSettings</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">="aspnet:MaxJsonDeserializerMembers"</span> <span class="attr">value</span><span class="kwrd">="10000"</span> <span class="kwrd">/></span><span class="kwrd"></</span><span class="html">appSettings</span><span class="kwrd">></span></pre></div><p>Hope this helps</p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com1tag:blogger.com,1999:blog-7316696847298400232.post-43860079026244335902012-06-27T02:24:00.000-07:002012-06-27T02:32:58.278-07:00Deleting Parent and its child record without setting ON CASCADE DELETE<p>Hello All,</p> <p>Very recent I found requirement for removing parent record which is having tons of relation as they have foreign key constrains; you can’t delete them unless you have ON CASCADE DELETE</p> <p>I found solution on <a href="http://stackoverflow.com/questions/116968/in-sql-server-2005-can-i-do-a-cascade-delete-without-setting-the-property-on-my">Stack Overflow</a> and base main article from <a href="http://www.sqlteam.com/article/performing-a-cascade-delete-in-sql-server-7">sqlteam</a>. I have modified procedure to fix some minor issue and here is the procedure which take table name and a query to filter row which we need to delete from table along with its reference.</p> <div id="box"><!-- code formatted by http://manoli.net/csharpformat/ --> <pre class="csharpcode"><span class="rem">-- ================================================</span><br /><span class="rem">-- Expects the name of a table, and a conditional for selecting rows</span><br /><span class="rem">-- within that table that you want deleted.</span><br /><span class="rem">-- Produces SQL that, when run, deletes all table rows referencing the ones</span><br /><span class="rem">-- you initially selected, cascading into any number of tables,</span><br /><span class="rem">-- without the need for "ON DELETE CASCADE".</span><br /><span class="rem">-- Does not appear to work with self-referencing tables, but it will</span><br /><span class="rem">-- delete everything beneath them.</span><br /><span class="rem">-- To make it easy on the server, put a "GO" statement between each line.</span><br /><span class="rem">-- ================================================</span><br /><span class="kwrd">CREATE</span> <span class="kwrd">PROCEDURE</span> DeleteCascade (<br /> @BaseTableName <span class="kwrd">VARCHAR</span>(200)<br /> ,@BaseCriteria <span class="kwrd">VARCHAR</span>(1000)<br />)<br /><span class="kwrd">AS</span> <span class="kwrd">BEGIN</span><br /><br /> <span class="kwrd">DECLARE</span> @ToDelete <span class="kwrd">TABLE</span> <br /> (<br /> Id <span class="kwrd">INT</span> <span class="kwrd">IDENTITY</span>(1, 1) <span class="kwrd">PRIMARY</span> <span class="kwrd">KEY</span> <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,<br /> Criteria <span class="kwrd">VARCHAR</span>(<span class="kwrd">5000</span>) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,<br /> TableName <span class="kwrd">VARCHAR</span>(200) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,<br /> Processed <span class="kwrd">BIT</span> <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,<br /> DeleteSql <span class="kwrd">VARCHAR</span>(<span class="kwrd">5000</span>)<br /> )<br /><br /> <span class="kwrd">SET</span> NOCOUNT <span class="kwrd">ON</span><br /><br /> <span class="kwrd">INSERT</span> <span class="kwrd">INTO</span> @ToDelete (Criteria,TableName , Processed)<br /> <span class="kwrd">VALUES</span> (@BaseCriteria, @BaseTableName, 0)<br /><br /> <span class="kwrd">DECLARE</span> @Id <span class="kwrd">INT</span><br /> <span class="kwrd">DECLARE</span> @Criteria <span class="kwrd">VARCHAR</span>(<span class="kwrd">5000</span>)<br /> <span class="kwrd">DECLARE</span> @TableName <span class="kwrd">VARCHAR</span>(<span class="kwrd">5000</span>)<br /><br /> <span class="kwrd">WHILE</span> <span class="kwrd">EXISTS</span>(<span class="kwrd">SELECT</span> 1 <span class="kwrd">FROM</span> @ToDelete <span class="kwrd">WHERE</span> Processed = 0) <br /> <span class="kwrd">BEGIN</span><br /> <br /> <span class="kwrd">SELECT</span> <span class="kwrd">TOP</span> 1 <br /> @Id = Id<br /> ,@Criteria = Criteria<br /> ,@TableName = TableName <br /> <span class="kwrd">FROM</span> @ToDelete <br /> <span class="kwrd">WHERE</span> Processed = 0 <br /> <span class="kwrd">ORDER</span> <span class="kwrd">BY</span> Id <span class="kwrd">DESC</span><br /><br /> <span class="kwrd">INSERT</span> <span class="kwrd">INTO</span> @ToDelete (Criteria, TableName, Processed)<br /> <span class="kwrd">SELECT</span> <br /> ReferencingColumn.name + <span class="str">' IN (SELECT ['</span> + ReferencedColumn.name + <span class="str">'] FROM ['</span> <br />+ @TableName +<span class="str">'] WHERE '</span> + @Criteria + <span class="str">')'</span>,<br /> ReferencingTable.name,0<br /> <span class="kwrd">FROM</span> sys.foreign_key_columns fk<br /> <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> sys.columns ReferencingColumn <br /> <span class="kwrd">ON</span> fk.parent_object_id = ReferencingColumn.object_id <br /> <span class="kwrd">AND</span> fk.parent_column_id = ReferencingColumn.column_id <br /> <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> sys.columns ReferencedColumn <br /> <span class="kwrd">ON</span> fk.referenced_object_id = ReferencedColumn.object_id <br /> <span class="kwrd">AND</span> fk.referenced_column_id = ReferencedColumn.column_id <br /> <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> sys.objects ReferencingTable <br /> <span class="kwrd">ON</span> fk.parent_object_id = ReferencingTable.object_id <br /> <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> sys.objects ReferencedTable <br /> <span class="kwrd">ON</span> fk.referenced_object_id = ReferencedTable.object_id <br /> <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> sys.objects constraint_object <br /> <span class="kwrd">ON</span> fk.constraint_object_id = constraint_object.object_id<br /> <span class="kwrd">WHERE</span> ReferencedTable.name = @TableName<br /> <span class="kwrd">AND</span> ReferencingTable.name != ReferencedTable.name<br /><br /> <span class="kwrd">UPDATE</span> @ToDelete <br /> <span class="kwrd">SET</span> Processed = 1<br /> <span class="kwrd">WHERE</span> Id = @Id<br /> <br /> <span class="kwrd">END</span><br /> <br /> <span class="kwrd">SELECT</span> <br /> <span class="str">'PRINT '</span><span class="str">'Deleting from '</span> + TableName + <span class="str">'...'</span><span class="str">'; DELETE FROM ['</span> + TableName + <span class="str">'] WHERE '</span> <br />+ Criteria <br /> <span class="kwrd">FROM</span> @ToDelete <br /> <span class="kwrd">ORDER</span> <span class="kwrd">BY</span> Id <span class="kwrd">DESC</span><br /> <br />END</pre><br /></div><br /><br /><p>When you execute this, you will see list of DELETE statement, which you need to run.</p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com3tag:blogger.com,1999:blog-7316696847298400232.post-55492533780947028352012-05-15T00:42:00.000-07:002012-05-15T00:48:15.670-07:00Enumeration Types as Bit Flags<p>An <span class="keyword">enum</span> is best practice to give intern<strike></strike>al constants to readable string format, example </p> <p><a href="http://lh3.ggpht.com/-dTGV5hJOB9w/T7IJNvDuT0I/AAAAAAAAAEM/yrBt-wgPZEo/s1600-h/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-qe5g95gX0ns/T7IJORF9muI/AAAAAAAAAEU/05iQTvMHNz8/image_thumb1.png?imgmax=800" width="231" height="148" /></a></p> <p>It’s very handy to use string rather to remember <span class="keyword">int</span> value and it also helps to maintain code if down the road we need to change integer value it wont be difficult. I am sure developer knows very well about how to use <span class="keyword">enum</span> in their code.</p> <p>The post is all about answering few question comes while development or requirement, How you pass multiple value by using <span class="keyword">enum</span>? or How to assign multiple <span class="keyword">enum</span> values to variable? or How can I store combination of <span class="keyword">enum</span> values using single <span class="keyword">enum</span> variable?</p> <p>All question have single answer, to use <span class="keyword">enum</span> as bit flags. In order to achieve this, you have to add new attribute Flags to your <span class="keyword">enum</span> declaration. As these values are bit you can use bitwise operation which are AND, OR, XOR and NOT.</p> <p>Let’s see useful example of Flag <span class="keyword">enum</span> using normal coding and then we will see same thing using Flags.</p> <p>In normal coding if I want to calculate discount for four country and more then one at same time, I rather create for methods and call four individual functions</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxBbtkp0kk2Wozzgj5ERbPsTFwczebp1_atJghf_QcignDk5zUiyRuVGak1yUae3ffZYqMnpGa4h0YBFV_SXAZWodI5HWmrJ4N_ozR0uCi9A5v-jckjbofBYqbJZqAy7vL4CvkMLLBbiw/s1600-h/image%25255B10%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT_HXlTxafQdwXjbt5YnZmxDZDzuWFJAOxIet-nzHQFUTT4aw15ex2_OrWUB5xT_L7Pg9NlnjmajhODSfp6M1lzO_bqhSDUqROcDqie_SxRwVffTjYMJH2aImCsk1Zb9p6M-l-JMf2aDc/?imgmax=800" width="737" height="356" /></a></p> <p>OR I can add <span class="keyword">bool</span> into signature for calculating particular discount.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzIX5ARn7bvKyeo57JUQC6W93xGjuX3JC5IEq0P-_xJRKNfio_3Q0Ri5lssHAIl9FgEIAkMjWzpkZEFpZjYAVKAvKkBRO_FvDFRizQ0PWJBeL8xMjMjQM2x43rkKo9Vg1qCE4go9LwIOw/s1600-h/image%25255B15%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC1H4XZPzcDImyOlW9SRNotDdGay6N7jkBKlSZJb3zin-vHAW9N4ZLClWn1qGJOlu8S95xknBWNEiKgF7ibCU_aa9ONYqEjlRIySMqkglDqnjz536eTV0IQCR2XAp7_FzZPew1_0jIkxY/?imgmax=800" width="733" height="408" /></a></p> <p>Drawback of first method is you have to keep adding new functions if you introduce new country and in second you have to pass false to country which you don’t want to do calculation, so signature will get increase in case we have more countries</p> <p>Now lets use Flag enumeration to avoid mention drawbacks.</p> <p>This will how your new <span class="keyword">enum</span> will look like</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK4brGvzelunbZ0K37mmLwwODQC7iMSJ9aT-Dk9pX7LPFveKciECHPgcA_cwUt14uBydWrgFv6SCXbjy1-47Pr0RC7aIuuuJ_5fPxNbk5-NQmcr7D8do7MwdwaVxMdgk4nvYq_bMT71Bk/s1600-h/image%25255B20%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNFPBcYWp56df7Arh0O_CRlGGOxpUzF-JGf6XP-7E9l1VvPssbNe6C7EY9mjQe49rrtzCW827yB416eVAj_sipQ03Zwp8Sr6kJBL5OmgK55EU7Xrmv4sTCT2VI2op5_-5jInKEnqjJJRk/?imgmax=800" width="216" height="164" /></a></p> <p>A new attribute called Flags is added and we have assigned constants in power or TWO, that is 1,2,4,8 and so on, so when we use in combination no one get overlap. </p> <p>Lets go ahead and create <span class="keyword">CalculateDiscount</span> function and use into our program.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPR-IWUPDAOCk-SF9hbXH6a5E7AiKBCYhODJxupmeXDhc0DQyHrO1MvmewJTgsztwy_olO8Q2ZBR1Pf0kkgsXQhs99lMm317hgk8APXGbiII8tj9n7LToB3VIhZ0VSDDkCyhqDvzK7S1A/s1600-h/image%25255B5%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibVDsYqt_1bmxPWyP8H3RA8mlH5KWNAkwMf5CLclHSmC6KJSLC1OCKEuvc852-zv3WfoAAsTck4bQZ2qJ9xezhc3M6yGhGeYYNTvyZNowAKqDnxLha08AAKbzXYJYF53VnKkeU4hcTDEg/?imgmax=800" width="745" height="582" /></a></p> <p>So single function <span class="keyword">CalculateDiscount</span> is responsible to calculate discount for four different country at a time. If I want to calculate discount for German and Canada, you can do that by passing both in single argument using ‘|’ operator, its bitwise OR operator. You can use ‘&’ bitwise AND operator to determine whether a specific flag is set or not.</p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com1tag:blogger.com,1999:blog-7316696847298400232.post-22816600915190981192012-04-04T04:34:00.000-07:002012-04-04T04:55:06.798-07:00Changing Physical Path of multiple Applications in IIS 7<p>Hello All,</p> <p>Usually, we need functionality where we have more then one set of application configured in our machine, like QA environment and DEV environment. We don’t have way to keep two directory pointing to same location in single web site. </p> <p>We can use backup feature for IIS 7 which helps to take backup as well as change directories of multiple applications at same time. First we are going to do backup IIS7</p> <p>Go to your inetsvr directory for your system’s system32 directory from command prompt. Make sure you are using Administrator account, if not then open command prompt with “run as administrator”</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzHufCMZqo-R8NWoQqcVkgm2brquVCD5i5jgjdH2SMIbPWFkG2hSJWKUjoVdJAn4_4n1AZYecxy-pENIuEmOgVZqWYAGpQnmcR-wGoRZ8S-3QIz0fS3rPOngU3zISbvDKEx0s3K1SGIeA/s1600-h/image%25255B18%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSU6R2xTZq603oTCEMY6uMeE5C5hhinO4uc3Xuf4Lz_eN-3e5z9xHfRBfiUhP-ruv90mHSTpnWpJzN_-Jz9JYgsx-QUf-FcwM3glVFriLJtGFGsAnkfeBO4TRsOmu6C_zeQMOiEm902Nw/?imgmax=800" width="660" height="211" /></a> </p> <p>Write following command in command prompt</p> <p>appcmd add backup NAME_OF_BACKUP</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDpz5r74JAm-KMuVOT0u5b1URKSjPdYY4E_x3MkZbeA9bmM51LTJfQAPbFjPYQ1uuA9ECskd653yEDTsniNfKXxuu5_BYcWYnKPCKpM-PjyaPxZBuvZrdNY7Rg3gxBgmOUihOxb1RJ2f0/s1600-h/image%25255B17%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-RjskHPDlqb4/T3wx3sduikI/AAAAAAAAADA/v4SwM2LWXVE/image_thumb%25255B11%25255D.png?imgmax=800" width="660" height="179" /></a></p> <p>I have created backup with name <em>IISBackup</em>, So we created backup of IIS including application pool, application, virtual directory etc. We will now change the physical path of more then one application and then restore backup back to IIS</p> <p>Open backup folder in explorer. </p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj59HieG_g8bFNSow2ykodAbRNxYjhvdG2ni5C7APU1y3Oe8G3auvB-v61hg1SvEw5a0iQImVfCfxf2DCESMmcwSFOY6bzWAO5UaPtF9CJbycSpB3VfzfnGOo1h4Pm8848VKRL2NxisyAA/s1600-h/image%25255B16%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg3WwcDoAeQ2e4phQNgNuZdg6c4myMJe-Bhy4lo-Jyapm6QCTifd61H3Lo0Ejtuxiww_TgUFY60DMYsWRTHOAq5CCXouFllxUOnqYd1xqRcqN1OaHeOXI7ImAdIC9HuRSf0FJYGcIYE2E/?imgmax=800" width="660" height="186" /></a></p> <p>Open that folder and edit applicationHost.config into notepad</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5s4ix7pxna8pWJGz2-J8jKIzGoaVUnkqMnOModi7C00-VTlXF4Ms82uKQuQOzUB-lIAXeWfg0WHaE2uZMu7RZ5o00jzMTpLHlou0ZbpO2-IqAPnF2N8KFYWiVotT4MJFduPdKC8UDENc/s1600-h/image%25255B28%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSx7EEcLt1Oxzy9w7dOz2AsBoM3i6IjExWdSUFolj5PBUuIqdLgVJ-ooKT5sm0nlBxqKvdl9XCsQqHewWrlzp7toiJsABNWxFwlUg3y4ZPflbd9HUnjfVDV0fT9Q32Wx5GmfA6emUSmvw/?imgmax=800" width="660" height="325" /></a></p> <p>In sites tag you can see your application with all details. Update physicalPath with your new path and save the file</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ7R8JKdnevHkZxdiR3J_9xy8Erfnc7d2NGdYtKvDIgJXDcsh51iJtSH678CZdyDe3PkysAwIgWJrG9HVkG6Xxv0W7AAd2dUSOfmZ9Sr1QklPkrHiIbxApWqL692YXAVGiWwrxcXfDLGI/s1600-h/image%25255B33%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvVWCF_Ofow6tsOHFuFTixnqGx3RnbhFVPhreaYzK3jxEaBAOUnOmnZbQ4J02cHxz9YCwj5JfTmxTGrXpjRF0iYLZTS7vhpYKlPLy0G6R0voAvpo-bNVyMtAe7NHYYWcscH9iIO6YD1jc/?imgmax=800" width="660" height="84" /></a></p> <p>Once you are done with this, go back to command prompt to restore our updated IIS settings, write following command, it will take few secs to set your new configurations.</p> <p>appcmd restore backup NAME_OF_BACKUP</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghUUAwALWAL9sSoqIejNImS1FwUz_jliOOYZdARCdVPbL-1iNqd4Fi46t8Q9EXGgDWpbjMWWHlGfY1F_8ZNA236bQHeJsWdgaUguz-8TxuVO93ykjl84hzwrERE3_JmhjHfN0hitON7h8/s1600-h/image%25255B38%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeC8eHV2g-lG2scBynjsg_AgbXZYHpNezDyKYIy4f_aHZ-85K4i3W5Z5folZ8_BBZke7V94bCw-WyPqf0odKZ__Nt1ysC1d23jCtOH61dzK1-IanJnhXh_7d2MwKDEENalK7IwBSTXty8/?imgmax=800" width="660" height="212" /></a></p> <p>You are done!</p> <p>So, we see how to backup and restore IIS, and how to change physical path of more then one applications.</p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com2tag:blogger.com,1999:blog-7316696847298400232.post-40241159898644233872011-06-28T06:40:00.001-07:002011-06-28T06:40:57.630-07:00Failed to Load Resource - Safari issue<p>Hello All,</p> <p>Recently application stopped working on Safari with issue 'Failed to Load Resource'. The scenario is; the web page send AJAX-Request to an aspx page and show the output into html container. The issue occurred when the request comes form https and with Safari. Basically all WebKit based browser having same issue, like Chrome and Safari.</p> <p>Post has been moved to <a href="http://beyondrelational.com/blogs/ibhadelia/archive/2011/06/28/failed-to-load-resource-safari-issue.aspx" target="_blank">beyondrelational.com</a></p> Imran.softwebhttp://www.blogger.com/profile/14785004731469357319noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-55714530257322645802011-06-26T03:18:00.001-07:002011-06-26T03:18:51.863-07:00An error occurred while opening the queue:Access is denied - MSMQ exception<p><font color="#808000"><em>System.ServiceModel.MsmqException: An error occurred while opening the queue:Access is denied. (-1072824283, 0xc00e0025). The  message cannot be sent or received from the queue. Ensure that MSMQ is installed and running. Also ensure that the queue is available to open with the required access mode and authorization.</em></font></p> <p>This post has been moved to <a href="http://beyondrelational.com/blogs/ibhadelia/archive/2011/06/21/an-error-occurred-while-opening-the-queue-access-is-denied-msmq-exception.aspx" target="_blank">beyondrelational</a>.</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com2tag:blogger.com,1999:blog-7316696847298400232.post-19731121562680029052011-06-02T01:36:00.001-07:002011-06-02T01:37:49.085-07:00Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated – Windows7 64bit - Solved<p>It have been long I wrote blog, planning to start this join once again</p> <p>Recently I changed my desktop from 32bit to 64bit Windows 7 and from there onwards I keep getting such issues. In such case when you run web page which gives following error.</p> <p><font color="#ff0000"><em>Error : Could not load file or assembly 'XXX.XXXXXX' or one of its dependencies. An attempt was made to load a program with an incorrect format.</em></font></p> <p><font color="#ff0000">Error: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.</font></p> <p>Read more <a href="http://beyondrelational.com/blogs/ibhadelia/archive/2011/06/02/failed-to-complete-setup-of-assembly-hr-0x8007000b-probing-terminated-windows7-64bit-solved.aspx" target="_blank">here</a>.</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-77932958952096929702010-07-31T11:11:00.000-07:002010-08-02T02:21:29.736-07:00Domain name replaced with Machine Name in WCF Service<p>This post has been moved to <a href="http://beyondrelational.com/blogs/ibhadelia/archive/2010/07/31/How-to-replaced-Machine-Name-with-Domain-name-in-WCF-Service-wsdl-link.aspx" target="_blank">beyondrelational</a>.</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-33390979557567553052010-07-17T10:12:00.001-07:002010-07-17T10:12:08.400-07:00How to get multiple result set of procedure using LINQ to SQL<p>There always be case where one procedure returns more then one result set. Getting those data in <em>DataSet</em> is lazy way of coding, best way to do that is using <em>DataReader</em>. <em>DataReader</em> having method call <em>NextResult</em> which allows us to read next result set if any.</p> <p>Read more from <a href="http://beyondrelational.com/blogs/ibhadelia/archive/2010/07/17/how-to-get-multiple-result-set-of-procedure-using-linq-to-sql.aspx" target="_blank">here</a>.</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com1tag:blogger.com,1999:blog-7316696847298400232.post-43927244107090433292010-07-16T10:03:00.001-07:002010-07-16T10:03:19.472-07:00How to add method in Sealed class<p><a title="http://beyondrelational.com/blogs/ibhadelia/archive/2010/07/16/how-to-add-method-in-sealed-class.aspx" href="http://beyondrelational.com/blogs/ibhadelia/archive/2010/07/16/how-to-add-method-in-sealed-class.aspx"><font color="#333333">It</font></a> is possible with C# 3.0 to add method into sealed class. For more details please visit following link</p> <p><a href="http://beyondrelational.com/blogs/ibhadelia/archive/2010/07/16/how-to-add-method-in-sealed-class.aspx">http://beyondrelational.com/blogs/ibhadelia/archive/2010/07/16/how-to-add-method-in-sealed-class.aspx</a></p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-82099848625474430162010-06-24T11:14:00.000-07:002010-06-25T11:24:47.944-07:00OperationFormatter could not serialize error with WCFI was working with calling WCF from iPhone, I have posted one post on “how can you call WCF from iPhone” you can find <a href="http://knowledgebaseworld.blogspot.com/2010/06/calling-wcf-service-from-iphone.html" target="_blank">here</a>. While I was working with this, I faced this issue and after doing some research I found solution! Here is what I did. <br /><br />Following operation contract works fine.<br /><br /><div id="box"><pre class="csharpcode">[OperationContract]<br /><span class="kwrd">public</span> Dictionary<<span class="kwrd">string</span>, <span class="kwrd">string</span>> GetDictionary()</pre></div><br />Note that I have only put operation contract not decoration which needed to work WCF with iPhone and Json. <br />But if we change this that operation contract to following...<br /><br /><div id="box"><pre class="csharpcode">[OperationContract]<br /><span class="kwrd">public</span> <span class="kwrd">string</span> GetDictionary()</pre></div><br />After doing this I started getting follwoing error.<br /><br /><em>The OperationFormatter could not serialize any information from the Message because the Message is empty</em><br /><br />I was wondering as it was issue with primitive type string! where it was working find with complex type. I searched a lot but did not get any solution for this. The service was retuning Serialized Json data; but not sure what was wrong there. I was searching for workaround to this but didn’t find any then I wrap that string into concert class and and return that class object, and you don’t believe it works fine! Error is gone I fixed <em>The OperationFormatter could not serialize any information from the Message because the Message is empty</em> error, wow!!!!! <br /><br />I have modified operation and now it looks like following.<br /><br /><div id="box"><pre class="csharpcode">[DataContract]<br /><span class="kwrd">public</span> <span class="kwrd">class</span> Response<br />{<br /> [DataMember]<br /> <span class="kwrd">public</span> <span class="kwrd">string</span> Data { get; set; }<br />}<br /><br />[OperationContract]<br /><span class="kwrd">public</span> Response GetDictionary()<br />{<br /> <span class="kwrd">return</span> <span class="kwrd">new</span> Response() { Data = <span class="str">"success"</span> };<br />}</pre></div><br />It still open question why it was not working in only string, however it was working with Dictionary object and then with Abstract type! I assume that at the time of serializing request its not able to create object of string as its primitive type! Not sure its true but it works fine with wrapper.Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-29747377438108387192010-06-22T19:30:00.000-07:002010-06-22T21:09:32.555-07:00wsdl-service-soap-address location having machine name not domain name<p>After fixing “Domain name replaced with machine name in WCF Service”, you can find solution in my previous <a href="http://knowledgebaseworld.blogspot.com/2010/06/domain-name-replaced-with-machine-name.html" target="_blank">post</a>.</p> <p>I found same issue but somewhere else, when you look into wsdl at the end where all services are listed there still machine name exists.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUywEErampp0hjnHbLhlo3JYNBUKcfVJ5U9o-8CWO31EovUWcnrfGDRo_OhCyGtRpbyTqSMTb4W7ZOX14juuSU9DxCR9XZS7GhXhcs8MXMS5qIg8ZYn1TlHP_9Jlvy2z8gwdsdVtH3/s1600-h/image%5B7%5D.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbWOt1gR5phVeKJW1IByDVuMX9gb2TgD-3R5oWcqJJI2ZXv67EyQzQdaKwyf9cIoaIzgC1r0X0Ln39a77bk2dLfxTcshQop4uGWxGsahhbGc2-15JxEcClWb-5TAdyWhG5A7P5b8yN/?imgmax=800" width="660" height="87" /></a> </p> <p>And hence any of the client will have following error.</p> <p><em>There was no endpoint listening at </em><a href="http://domainname/ServiceName.svc"><em>http://domainname/ServiceName.svc</em></a><em> that could accept the message. This is often caused by an incorrect address or SOAP action.</em> </p> <p>That is because it still uses computer name in soap address not domain name. Lets fix this issue too. We have to simply change endpoint address nothing more.</p> <div id="box"> <pre class="csharpcode"><span class="kwrd"><</span><span class="html">services</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">service</span> <span class="attr">behaviorConfiguration</span><span class="kwrd">="serviceBehaviour"</span> <span class="attr">name</span><span class="kwrd">="Demo.Service.MultiEndPointsService"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">endpoint</span> <span class="attr">address</span><span class="kwrd">="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic"</span> <span class="attr">binding</span><span class="kwrd">="basicHttpBinding"</span> <span class="attr">bindingConfiguration</span><span class="kwrd">="basicBinding"</span><br /> <span class="attr">contract</span><span class="kwrd">="Demo.Service.MultiEndPointsService"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">service</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">services</span><span class="kwrd">></span><br /><span class="kwrd"><</span><span class="html">behaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">serviceBehaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">behavior</span> <span class="attr">name</span><span class="kwrd">="serviceBehaviour"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">serviceMetadata</span> <span class="attr">httpGetEnabled</span><span class="kwrd">="true"</span> <span class="attr">httpGetUrl</span><span class="kwrd">="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">serviceDebug</span> <span class="attr">includeExceptionDetailInFaults</span><span class="kwrd">="false"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">behavior</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">serviceBehaviors</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">behaviors</span><span class="kwrd">></span></pre></div><br /><p>Now let’s how wsdl looks like.</p><a href="http://lh5.ggpht.com/_BE0RbE03Yi8/TCGIBVrq3TI/AAAAAAAAAeE/9IYfJpX6T5E/s1600-h/image%5B11%5D.png" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT3D3imvG6eNKefHDd9rgfs3i27jj1VqJWcLK7f27-FZbC-pnoHvmoRYQzbUb7V5MGq9s0v1gCR9pNS7EL9CSfzRu7UikhDdD_wHswodlmZmMsMcWMO4FxjxTCzIgE9BvdjNmm_-CL/?imgmax=800" width="660" height="96" /></a><br /><p>We are good to go!</p>Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com8tag:blogger.com,1999:blog-7316696847298400232.post-43635436488891230992010-06-22T05:30:00.000-07:002010-06-22T10:12:24.169-07:00Domain name replaced with Machine Name in WCF Service<p>I personally came across this issue <em>WCF was taking machine name not IP address or domain name</em> and also I got questions from forums about “<em>how to replaced Machine Name with Domain name in WCF Service wsdl link?</em>”. This occurs when we host WCF service on IIS then the links to wsdl is uses local machine name not the domain name or IP address. </p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6NkCLNrB0T8v6oCEh5a4g0jTwXZ8ziCxpDrI5agAU34dPfRIEEBqfCv4WgPGp04zhp6gDWM6NdRhDU9B3shZe57KhZA__-fNWmcD3XemtVGtYDuULUbMSRJbJfrSCOZqll0UPvmfn/s1600-h/image40.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_BE0RbE03Yi8/TCDtrcYLvGI/AAAAAAAAAdo/Y6yJa6sB2iI/image_thumb28.png?imgmax=800" width="660" height="296" /></a> </p> <p>You can see in browser [here I used IP address of my machine] in wsdl link its adding my computer name, this is same issue when I publish this service on production; the wsdl link is taking name of production machine not domain.</p> <p>I found some solutions which changes the bindings on server but again that is not helpful for me on production server however it works well on local machine. </p> <p>Then I was checking the configurations and found solution for how Domain name replaced with Machine Name in WCF Service without playing with IIS bindings. In service behavior we can change the behavior of <em>serviceMetadata</em> which will <strong>FIX</strong> our problem. We need to specify on what location metadata will resides <em>httpGetUrl</em> or <em>httpsGetUrl</em>. We can add url having domain rather machine name. So final configuration should look like following which is our solution.</p> <div id="box"><pre class="csharpcode"><span class="kwrd"><</span><span class="html">system.serviceModel</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">services</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">service</span> <span class="attr">name</span><span class="kwrd">="Demo.Service.MultiEndPointsService"</span> <span class="attr">behaviorConfiguration</span><span class="kwrd">="serviceBehaviour"</span><span class="kwrd">></span> <br /> <span class="kwrd"><</span><span class="html">endpoint</span> <span class="attr">address</span><span class="kwrd">="basic"</span> <span class="attr">binding</span><span class="kwrd">="basicHttpBinding"</span> <span class="attr">bindingConfiguration</span><span class="kwrd">="basicBinding"</span> <span class="attr">contract</span><span class="kwrd">="Demo.Service.MultiEndPointsService"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">service</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">services</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">behaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">serviceBehaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">behavior</span> <span class="attr">name</span><span class="kwrd">="serviceBehaviour"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">serviceMetadata</span> <span class="attr">httpGetEnabled</span><span class="kwrd">="true"</span> <span class="attr">httpGetUrl</span><span class="kwrd">="http://192.168.3.61/Demo.Service/MultiEndPointsService.svc/basic"</span> <span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">serviceDebug</span> <span class="attr">includeExceptionDetailInFaults</span><span class="kwrd">="false"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">behavior</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">serviceBehaviors</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">behaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">bindings</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">basicHttpBinding</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">binding</span> <span class="attr">name</span><span class="kwrd">="basicBinding"</span> <span class="attr">maxBufferSize</span><span class="kwrd">="2147483647"</span> <span class="attr">maxReceivedMessageSize</span><span class="kwrd">="2147483647"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">security</span> <span class="attr">mode</span><span class="kwrd">="None"</span><span class="kwrd">></</span><span class="html">security</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">readerQuotas</span> <span class="attr">maxStringContentLength</span><span class="kwrd">="2147483647"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">binding</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">basicHttpBinding</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">bindings</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">system.serviceModel</span><span class="kwrd">></span></pre></div><p>You can see value of <em>httpGetUrl</em>; I have specified IP address </p><p><a href="http://lh4.ggpht.com/_BE0RbE03Yi8/TCDtsN2jSsI/AAAAAAAAAds/_PUhY70-XaE/s1600-h/image43.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_BE0RbE03Yi8/TCDts20_luI/AAAAAAAAAdw/vQ8smyjJccQ/image_thumb31.png?imgmax=800" width="660" height="69" /></a> </p><p>Now let’s see again in browser.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMF2MnHWQF_L4r_zqqEzOVS7fsiTuSNgV9fqSfto7ijoNrsN0pUqDZN6eXponBWgrX9jgzHANsa4msklyYoxE5TAvtPjBCJUZIuII80Q2FoEy6HMLS9fVtJfNS2OKBDSzSAp74t7g3/s1600-h/image46.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit8QaaiGjiPaFpDHEXP53zp7Jhg75eNSeYicfdeB2CRcLFaTirBZpHWWnDoGn3_CPY6ci2rKM_-q1b-XRJcI4e7ftun__0SU-boHjLpRsvJMeSBUSa3iC3qYXHtDTCGBs7Cf0tQY7w/?imgmax=800" width="754" height="328" /></a> </p><p>There you goo!!!</p>Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com26tag:blogger.com,1999:blog-7316696847298400232.post-16343110435074615432010-06-21T09:52:00.000-07:002010-06-22T10:03:21.481-07:00Calling WCF service from iPhone<p>WCF changes way of communication between application-to-application and intra-application. This post will help you to call WCF from iPhone application. First we will see what we have to do on WCF to let iPhone application call service. And the sample code which call WCF from iPhone.</p><p>First let’s create simple WCF service.</p><div id="box"><pre class="csharpcode">[ServiceContract(Namespace = <span class="str">""</span>)]<br />[DataContractFormat]<br /><span class="kwrd">public</span> <span class="kwrd">class</span> MultiEndPointsService<br />{<br /> [OperationContract]<br /> <span class="kwrd">public</span> <span class="kwrd">string</span> GetDictionary()<br /> {<br /> Dictionary<<span class="kwrd">string</span>, <span class="kwrd">string</span>> dict = <span class="kwrd">new</span> Dictionary<<span class="kwrd">string</span>, <span class="kwrd">string</span>>();<br /> dict.Add(<span class="str">"IB"</span>, <span class="str">"Imran Bhadelia"</span>);<br /> dict.Add(<span class="str">"DO"</span>, <span class="str">"David Oliver"</span>);<br /> dict.Add(<span class="str">"NA"</span>, <span class="str">"Nick Althoff"</span>);<br /> dict.Add(<span class="str">"JJ"</span>, <span class="str">"Jay Joshi"</span>);<br /> dict.Add(<span class="str">"DL"</span>, <span class="str">"Dave Larson"</span>);<br /> dict.Add(<span class="str">"BA"</span>, <span class="str">"Brenda Ayong-Chee"</span>);<br /> dict.Add(<span class="str">"JP"</span>, <span class="str">"Jay Parikh"</span>);<br /><br /> StringBuilder sbJson = <span class="kwrd">new</span> StringBuilder();<br /> <span class="kwrd">new</span> JavaScriptSerializer().Serialize(dict, sbJson);<br /> <span class="kwrd">return</span> sbJson.ToString();<br /><br /> }<br />}</pre></div><br /><p>This is simple WCF Service. We need to add some decoration for enabling web script and handle POST method. We are going to send http post form iPhone application and send Json string as response. Doing so we also need to decorate our operation contract to set request and response format. </p><div id="box"><pre class="csharpcode">[ServiceContract(Namespace = <span class="str">""</span>)]<br />[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br />[ServiceBehaviorAttribute(IncludeExceptionDetailInFaults = <span class="kwrd">true</span>)]<br />[DataContractFormat(Style = OperationFormatStyle.Document)]<br /><span class="kwrd">public</span> <span class="kwrd">class</span> MultiEndPointsService<br />{<br /> [WebInvoke(Method = <span class="str">"POST"</span>, BodyStyle = WebMessageBodyStyle.WrappedRequest,<br /> RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json)]<br /> [OperationContract]<br /> <span class="kwrd">public</span> <span class="kwrd">string</span> GetDictionary()<br /> {<br /> Dictionary<<span class="kwrd">string</span>, <span class="kwrd">string</span>> dict = <span class="kwrd">new</span> Dictionary<<span class="kwrd">string</span>, <span class="kwrd">string</span>>();<br /> dict.Add(<span class="str">"IB"</span>, <span class="str">"Imran Bhadelia"</span>);<br /> dict.Add(<span class="str">"DO"</span>, <span class="str">"David Oliver"</span>);<br /> dict.Add(<span class="str">"NA"</span>, <span class="str">"Nick Althoff"</span>);<br /> dict.Add(<span class="str">"JJ"</span>, <span class="str">"Jay Joshi"</span>);<br /> dict.Add(<span class="str">"DL"</span>, <span class="str">"Dave Larson"</span>);<br /> dict.Add(<span class="str">"BA"</span>, <span class="str">"Brenda Ayong-Chee"</span>);<br /> dict.Add(<span class="str">"JP"</span>, <span class="str">"Jay Parikh"</span>);<br /> <br /> StringBuilder sbJson = <span class="kwrd">new</span> StringBuilder();<br /> <span class="kwrd">new</span> JavaScriptSerializer().Serialize(dict, sbJson);<br /> <span class="kwrd">return</span> sbJson.ToString();<br /> }<br />}</pre></div><br /><p>And following are the configuration settings</p><div id="box"><pre class="csharpcode"><span class="kwrd"><</span><span class="html">system.serviceModel</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">services</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">service</span> <span class="attr">name</span><span class="kwrd">="Demo.Service.MultiEndPointsService"</span> <span class="attr">behaviorConfiguration</span><span class="kwrd">="serviceBehaviour"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">endpoint</span> <span class="attr">address</span><span class="kwrd">="basic"</span> <span class="attr">binding</span><span class="kwrd">="basicHttpBinding"</span> <span class="attr">bindingConfiguration</span><span class="kwrd">="basicBinding"</span> <span class="attr">contract</span><span class="kwrd">="Demo.Service.MultiEndPointsService"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">service</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">services</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">behaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">serviceBehaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">behavior</span> <span class="attr">name</span><span class="kwrd">="serviceBehaviour"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">serviceMetadata</span> <span class="attr">httpGetEnabled</span><span class="kwrd">="true"</span> <span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">serviceDebug</span> <span class="attr">includeExceptionDetailInFaults</span><span class="kwrd">="false"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">behavior</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">serviceBehaviors</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">behaviors</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">bindings</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">basicHttpBinding</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">binding</span> <span class="attr">name</span><span class="kwrd">="basicBinding"</span> <span class="attr">maxBufferSize</span><span class="kwrd">="2147483647"</span> <span class="attr">maxReceivedMessageSize</span><span class="kwrd">="2147483647"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">security</span> <span class="attr">mode</span><span class="kwrd">="None"</span><span class="kwrd">></</span><span class="html">security</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">readerQuotas</span> <span class="attr">maxStringContentLength</span><span class="kwrd">="2147483647"</span> <span class="kwrd">/></span><br /> <span class="kwrd"></</span><span class="html">binding</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">basicHttpBinding</span><span class="kwrd">></span> <br /> <span class="kwrd"></</span><span class="html">bindings</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">system.serviceModel</span><span class="kwrd">></span></pre></div><br /><p>We need to create basicHttpBinding so it get called form iPhone application, we haven’t sent security to call this method; and following is the Objective-C code which call WCF from iPhone.</p><div id="box"><pre class="csharpcode">NSString *soapMessage = [NSString stringWithFormat:@"<span class="kwrd"><</span><span class="html">SOAP-ENV:Envelope</span> <span class="attr">xmlns:SOAP-ENV</span>=\<span class="kwrd">"http://schemas.xmlsoap.org/soap/envelope/\"</span><span class="kwrd">><</span><span class="html">SOAP-ENV:Body</span><span class="kwrd">><</span><span class="html">GetDictionary</span><span class="kwrd">></</span><span class="html">GetDictionary</span><span class="kwrd">></</span><span class="html">SOAP-ENV:Body</span><span class="kwrd">></</span><span class="html">SOAP-ENV:Envelope</span><span class="kwrd">></span>"];<br /> <br />NSURL *url = [NSURL URLWithString:@<a href="http://localhost/Demo.Service/MultiEndPointsService.svc/basic">http://localhost/Demo.Service/MultiEndPointsService.svc/basic</a>];<br />NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; <br />NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; <br /> <br />[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];<br />[theRequest addValue: @"urn:MultiEndPointsService/GetDictionary" forHTTPHeaderField:@"SOAPAction"];<br />[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];<br />[theRequest setHTTPMethod:@"POST"]; <br />[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];<br /><br />NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];</pre></div><p>Once you parse the response it will look like following.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6e2J_pZ6j-7x2vDAriZ9cOXYjbAiXm8wmmQ9Ebcbi46Zh-Lm2idIxh_YtRLvuCbLLdOxmGgKMrCgazPC_HX05fKWTftPX7AOgK1KUuWuFiY8Vq2EtJjHttzNUCuPjkUif97j_QtyC/s1600-h/wsdl2.png"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="wsdl" border="0" alt="wsdl" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhp9ugh8k94KGHIQaSPghISmOw2JHV4jUr27kA2K-n0aVM2m5326Zl_P8DeiFfTro6LqtNpVWD7SuRLPQsEhvQvxzBLVv6RLk0QgdQDXp-Fu5Eu2l3jyt1T5HNRaF4dcyKaaJVOEZu/?imgmax=800" width="269" height="490" /></a></p><p>You can also call operation contract having parameters, for that need to create proper message and then add it in SOAP-BODY that will work.</p>Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com15tag:blogger.com,1999:blog-7316696847298400232.post-89034075286970130542010-06-20T04:51:00.001-07:002011-10-04T22:07:09.741-07:00WCF Service with webHttpBinding-basicHttpBinding-wsHttpBinding<p>WCF Services are designed to support distributed services where consumed client. Services are typically have WSDL interface which any of client can consumed regardless of platform on which WCF is hosted on. </p><p>WCF Services having three portions, Class having methods, host environment to host service, and one or more endpoints. Endpoints is place where WCF Client connects to WCF Service. In order to accommodate different communication scenario you just need to create more then one endpoints, for each endpoint you specify the address, a binding and a contract. Address is simple listener; contract specify the format of message which will arrive on specified address and binding is let you configure transport protocol, encoding and security. There are few built-in bindings represented by <em>System.ServiceModel.Channels.Binding</em> class to support HTTP, TCP and MSMQ protocols.</p><p>That was brief about WCF, now lets come to our business. We need to use wsHttpBinding + basicHttpBinding + webHttpBinding all together. That means we need to have multiple ends points to our service for different-different scenario. Here are the Service contract and operation contracts which we are going to use.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirCOglRAin781azHq0lHEpipQz73RDEwpi5GqiuJwZwzFFXC70TCcT95BK5vxEHfrC26kzKZXEJduMlz2x_r2XCAOkHlxK0BmiKlmj0aOifXIIeEv4AIRlB5vMyAzQCX-nVmMQ6Now/s1600-h/image%5B10%5D.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_BE0RbE03Yi8/TB4Ahwhb6rI/AAAAAAAAAcY/7sStZslR9cg/image_thumb%5B4%5D.png?imgmax=800" width="603" height="373" /></a> </p><p>We will add one by one binding and check into WCF Test Client. First we will add basicHttpBinding which is designed for interoperability utmost important, its using SOAP 1.1.</p><p><a href="http://lh6.ggpht.com/_BE0RbE03Yi8/TB4AjOcDx0I/AAAAAAAAAcc/1roBG4v3tn4/s1600-h/image%5B14%5D.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_BE0RbE03Yi8/TB4AkDcYofI/AAAAAAAAAcg/mKVMAjTVItI/image_thumb%5B6%5D.png?imgmax=800" width="660" height="347" /></a> </p><p>You can see single endpoints having address and bindings, we have added binding configuration name <em>basicBinding</em>, which have property like <em>security mode</em> to <em>None</em>, <em>readerQuotas</em> having setting for client who is reading data from channel, also <em>maxBufferSize</em> which is parameter defined size which can be passed thru channel. We can see bindings in WCF Test Client it will show basic http bindings having one method. The value of <em>maxBufferSize</em> and <em>maxReceivedMessgaeSize</em> should be same for transfer mode is buffered. We have added behavior configuration for our service; <em>serviceMetadata httpGetEnabled="true"</em> allows simple HTTP Get request to succeed for metadata retrieval, by default WCF does not exposed metadata. </p><p>We can use WCF Test Client to check whether our setting are correct or not. So open WCF Test Client and add service url into service project.</p><p><a href="http://lh4.ggpht.com/_BE0RbE03Yi8/TB4AlhXLnKI/AAAAAAAAAck/Q9ryjSXhzMg/s1600-h/image9.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_BE0RbE03Yi8/TB4AmEnzgpI/AAAAAAAAAco/nNaZ2AOWjrI/image_thumb2.png?imgmax=800" width="441" height="176" /></a> </p><p>It shows that we have exposed our service using basicHttpBinding. Now lets add wsHttpBinding binding, which is design for security, reliable messaging and transactions and its using SOAP 1.2 along with WS-Addressing 1.0 for message version which will carry additional protocol headers.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMyQySy8f2w20PRYUGnOrUOueR5xpUZU8Cx6yzcXkN7e3cRX5FadnJxS7VYJipn2Rqk6sML7-lhHMBHRFFii7trVyrszFf4-GmrHeui5m5bNzQRJLJAcl7eGu6oSUzYkeC8SUkvSL1/s1600-h/image%5B19%5D.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglRd1WpLXCnty2eLFzDD2YjHvXCdzBr5E1ASKgkfNm_quPbLZp_HsXStCVYneCDH_7GD_EnJwjfXvsnZCEX8PynTEwzg2KROrYuPanx3BFGRdScNBDtwVKbC2XNsDruDLkZqTS61BX/?imgmax=800" width="644" height="388" /></a> </p><p>We have added binding configuration to set security and session reliability. The reliable session WCF provides ensures that messages sent between endpoints are transferred across SOAP or transport intermediaries and are delivered only once and, optionally, in the same order in which they were sent</p><p>Now let’s check on our WCF Test Client.</p><p><a href="http://lh6.ggpht.com/_BE0RbE03Yi8/TB4ApHsPQUI/AAAAAAAAAc0/pHAyt6C7i88/s1600-h/image%5B6%5D.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXHdEjN-c2K8DtNweQR0GGNMRKAZIzucUfYo49c50AaDtTOSNuKOVRSaip7tlUhP-XSa6COoWhRdljBcN74pjBhu0GkeQOF9Ytlrhs3wkYiC9L_lLPAshoiMNVuFOjqj8XAwSnI2DL/?imgmax=800" width="453" height="208" /></a> </p><p>So, we can see two endpoints has been exposed, one is for basic binding and other is web script bindings. We already add basic and ws bindings lets add now web bindings.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_BCzoC9TL62DgAks_gOrsHTLBvDLsKYe6erXp8zjYHceNY2LGvMofH8EW-vPnMrwFAPoUFv-Br3Yx4Lm__fj_Qs7uLCHY9o1Qz0tiS2aAvJQepaVaOFW2WdIff_HQEuzGrwHIquPz/s1600-h/image%5B27%5D.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgizCaSZg12m_KJBeeJbdtKWaK_sMW_aHqqTKY19XKbq0_Y2F3nT5fB0-rSbjcKx-V8s2X70nkZ0MACwCCVjSji162HJ-DJ0b9Ks2sN1svnvKP8JN0oXXE9j1KqSzDL9YYdhc691I2O/?imgmax=800" width="688" height="239" /></a> </p><p>One more endpoint, it’s now easy to expose more then one endpoint for single operation contract. If you need any security or additional settings then you can add binding configuration for this endpoint, but for now we don’t need any configurations. Let’s check our WCF Test Client.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQljLthLnfE7-nfu9DFc4wsp8zqtwMrx_AOxfn1NLX1rEdD0Q4QLCGwlAJjraWQXpDxgNi2GYiApnZQfPUOodNFecefNQQZtl__S-gLDonj_2jBnbFveIy6LfnmWs4TjMb8e_hLw12/s1600-h/image%5B30%5D.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioU9Ptm3N-RMtBFlEjBqc6Ru7BvSawCVhi-08L5SgoLbzX4PEczLpKi22u6ChIvM7Fpw3x-jttb5ZAxoTm0ZnGF9zd-_2EVm00MmKXk-MuYqeSYZYJcwgTOr_5vBJpNdcJ9i7II-O9/?imgmax=800" width="387" height="215" /></a> </p><p>We can see all these three binding for single operation contract! You can see wsdl file which will expose all these three bindings.</p><p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB_5Iyyfl8JD7p4EFOzRCDrlluwcy9ZbW2ZtZ6DDHGdPiUmDlh7XNXzGZSHu04GpAZV9XUvK7VCgeEGEmXYhyEOw0ki9_jSf8rZ55Yk2szz3kjLrxvQtnFXEilJtdzVe4YOMp-G3UC/s1600-h/image%5B34%5D.png" target="_blank"><img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3PVJYOZ__JGyTgbeHvijeKYaMVKoq3h0AK87GLlviYYfTTq_quzwAw9of0AGGRI9SlP5vd6UyuA4N-u9ecpirLLg3ptti3mrQvmyZV6EXR_prDOKmipYi9JcQTmtzExU7xD123vGG/?imgmax=800" width="707" height="139" /></a> </p><p>So we have exposed webHttpBinding + basicHttpBinding + wsHttpBinding endpoints in WCF service using same operation contract. We can use webHttpBinding for Silverlight application and also Json call.</p>Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com14tag:blogger.com,1999:blog-7316696847298400232.post-28726992190733789222010-06-14T11:08:00.000-07:002010-06-19T11:12:59.277-07:00RadComboBox dropdown issue in IE<p>Hello All, I was facing issue with RadComboBox dropdown, its adding scrollbar in IE if an item is longer then default size.</p><p> <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyAlrgaadOPJS-Vj1Ar4m6d5tCDKVaJc1h_4xYyk7EX3AgsDphpAXpVjvPKAhyphenhyphennif5k1joLdHaqZW5mhC7N9dz3P0vYQbO5H_kZuqcoDFhYmFnCUUGwDjqP1vnrpQBNHcmAGw30dRc/s1600-h/image2.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJDDcr3r8NjFef-9xI95nk1xGyL5V8fGanabB-_fEPoQ3HTFpTg_zxW16-i4lJC-ceOQP9Oeir0L7dkLEBWMTv2qe8lc55GWkiDh8kwc0BtkSaoGVjNwsJL49YOMNzCmIyA-FNh3p8/?imgmax=800" width="221" height="157" /></a> </p><p>This is normal behavior, as we have item which get fits into dropdown, now consider following case where we items which are little longer then before. </p><p><a href="http://lh4.ggpht.com/_BE0RbE03Yi8/TB0H0Ll-gSI/AAAAAAAAAb0/BbFWVNPFvKk/s1600-h/image5.png" target="_blank"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_BE0RbE03Yi8/TB0H1CoWSJI/AAAAAAAAAb4/s68PF8ILb78/image_thumb1.png?imgmax=800" width="258" height="182" /></a> </p><p>Here you can see horizontal scrollbar is appear as our text is little bit longer then <em>min-width</em> property. Min-width property allow you to set minimum width of dropdown. But this looks weird. </p><p><strong>Solution</strong>: You need to override following default style of RadComboBox. </p><div id="box"><pre class="csharpcode"><span class="kwrd"><</span><span class="html">style</span><span class="kwrd">></span><br /> .rcbSlide div<br /> {<br /> width: auto !important;<br /> min-width: 150px !important;<br /> max-width: 400px !important;<br /> }<br /> .rcbList<br /> {<br /> position: relative !important;<br /> }<br /><span class="kwrd"></</span><span class="html">style</span><span class="kwrd">></span></pre></div><br /><p>We can see after applying this style into page, RadComboBox will look like following.</p><a href="http://lh4.ggpht.com/_BE0RbE03Yi8/TB0H2GbOCYI/AAAAAAAAAb8/Ol19h8rDUi4/s1600-h/image%5B3%5D.png" target="_blank"><img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title="image" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy9e9cgaOgc2t0G4GRcpMUl5_xgezowhy4uDDQpam0lR3T9dAJdyshL55rjgLO15qfYQdH3ZQUxvMFl2Bp836qP9mxzBID0LQMitgjpzJ-91MhfwXKxpjX6uRw401ck8-9R3dlIyfX/?imgmax=800" width="304" height="129" /></a>Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com1tag:blogger.com,1999:blog-7316696847298400232.post-80421024670697989012010-04-17T00:10:00.000-07:002010-04-17T00:12:28.151-07:00HTTP Error 404.17 - Not Found with IIS7 and WCF<p>Hello All,</p> <p>I was running to same issue when I have installed VS2010 on Windows 7 after installing .NET on IIS 7.5. My WCF service was retuning me the following error when I try to hit my wcf service it will giving me following error.</p> <p><font color="#ff0000">HTTP Error 404.17 - Not Found</font></p> <p>I tried to change application pool and switch form 2.0 classic to 4.0 class, and then it gives me one more error!</p> <p><font color="#ff0000">HTTP Error 500.19 – Internal Server Error <br />The requested page cannot be accessed because the related configuration data for the page is invalid. </font></p> <p><font color="#ff0000">Error Code 0×800700b7 <br />Config Error There is a duplicate ’system.web.extensions/scripting/scriptResourceHandler’ section defined</font></p> <p>After doing some search I found out the fix of this, we just need to register service model using following command, you should run command prompt in administrator mode and then go to following directory.</p> <blockquote> <p><em><strong><font face="Arial">$WindowsDir$\Microsoft.NET\Framework\v3.0\Windows Communication Foundation</font></strong></em> </p> </blockquote> <p>And run this command in favor to register service model. </p> <blockquote> <p><em><strong><font face="Arial">servicemodelreg –i</font></strong></em></p> </blockquote> <p>It will install machine configuration sections, handlers, assemblies, modules, protocols and lots of other thing to work things properly.</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com5tag:blogger.com,1999:blog-7316696847298400232.post-91059277807049249592010-03-16T03:54:00.000-07:002010-03-26T10:38:50.303-07:00Two WCF Sharing same a Data Contract - Ambiguous Error<span style="color:#808000;"><strong>[Problem: Ambiguous reference]</strong></span><br /><br />Hello All,<br /><br />I came across one common issue while working with WCF services, Two WCF exposing same data contract with different namespace. Here are my two service contract with operation contracts.<br /><br /><div id="box"><pre class="csharpcode"><span class="kwrd">namespace</span> SVCDataContractTest.WCF<br />{<br /> [ServiceContract]<br /> <span class="kwrd">public</span> <span class="kwrd">interface</span> IService1<br /> {<br /> [OperationContract]<br /> <span class="kwrd">void</span> DoWork(UserInfo userInfo);<br /><br /> [OperationContract]<br /> <span class="kwrd">void</span> SaveContact(ContactInfo contactInfo);<br /><br /> }<br /><br /> <span class="kwrd">public</span> <span class="kwrd">class</span> Service1 : IService1<br /> {<br /> <span class="kwrd">public</span> <span class="kwrd">void</span> DoWork(UserInfo userInfo)<br /> {<br /> <span class="rem">//Do some work</span><br /> }<br /><br /> <span class="kwrd">public</span> <span class="kwrd">void</span> SaveContact(ContactInfo contactInfo)<br /> {<br /> <span class="rem">//Do some work</span><br /> }<br /> }<br /><br /> [ServiceContract]<br /> <span class="kwrd">public</span> <span class="kwrd">interface</span> IService2<br /> {<br /> [OperationContract]<br /> UserInfo DoWork();<br /> }<br /><br /> <span class="kwrd">public</span> <span class="kwrd">class</span> Service2 : IService2<br /> {<br /> <span class="kwrd">public</span> UserInfo DoWork()<br /> {<br /> <span class="rem">//Do some work</span><br /> <span class="kwrd">return</span> <span class="kwrd">new</span> UserInfo();<br /> }<br /> }<br />}</pre></div><br />While adding them as reference it will generate two separate class having different namespace, we are good here as there won't be any compilation error if a requester don't import both namespace.<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfFmIQSPjDQcBxjKl9aC8YWUkqwvnXcHoLK8qCdEftrd7E6sSAZcc1ea-OEejG2699L8TcSkX5eBYPsA0MZ7du424GwpzGZ6c5nwAJIPrJ9N4QEFEY0xxtJed0rBJGq5_J87Eutu8O/s1600-h/ServiceReferenceClassDiagram.jpg"><img style="cursor:pointer; cursor:hand;width: 789px; height: 279px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfFmIQSPjDQcBxjKl9aC8YWUkqwvnXcHoLK8qCdEftrd7E6sSAZcc1ea-OEejG2699L8TcSkX5eBYPsA0MZ7du424GwpzGZ6c5nwAJIPrJ9N4QEFEY0xxtJed0rBJGq5_J87Eutu8O/s400/ServiceReferenceClassDiagram.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5452061119019073426" /></a><br /><br />You can see there two <span class="keyword">UserInfo</span> classes. Now problem comes when you imported both of the namespace, what happen to your class? it will start giving you following error.<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizz3hgDKD355JgqrEbqjJ2OwfsOqU64tfR-SFoWccLKXaJkcmvrxRkB6D1gjozx2Bo72FhfQ9Q68D2v3jbCnBcEYfcWyX2pR7h85JL_cCEicpIXC79F27wP-peraGWRWDWQn-9rX0o/s1600/Error.jpg"><img style="cursor:pointer; cursor:hand;width: 640px; height: 187px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizz3hgDKD355JgqrEbqjJ2OwfsOqU64tfR-SFoWccLKXaJkcmvrxRkB6D1gjozx2Bo72FhfQ9Q68D2v3jbCnBcEYfcWyX2pR7h85JL_cCEicpIXC79F27wP-peraGWRWDWQn-9rX0o/s400/Error.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5452997645875724162" /></a><br /><br />It says that <span class="keyword">UserInfo</span> is an ambiguous, as there are two set of classes resides in reference. The problem is when you add Service reference it's not treating <span class="keyword">UserInfo</span> class as Shared class. Solution for this is to create Proxy with Type Sharing. We can use <span class="keyword">wsdl.exe</span> to create proxy with <span class="keyword">shareType</span> switch<br /><br /><div id="box"><pre class="csharpcode">wsdl.exe /out:ServiceProxies.cs /<strong>shareTypes</strong> http://localhost/SVCDataContractTest.WCF/Service1.svc?wsdl http://localhost/SVCDataContractTest.WCF/Service2.svc?wsdl</pre></div><br />This will result in one class file called <span class="keyword">ServiceProxies</span>, which contains the proxy implementation of both service but the implementation of <span class="keyword">UserInfo</span> will be single.<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBgbXd8A7-kKgkpkBNMmsQRuVCkWUgrbdEMhWYI_OsZAmOKcrf25AtQ6OwbsONH5h1SdXEdd7r53M-BH6isXnUipgy6TZFrqXZFy8ZrTE1Nah1wP9SH4TzaJLOkrRlXggoqjrPWk_7/"><img border="0" alt="ProxyCD1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBgbXd8A7-kKgkpkBNMmsQRuVCkWUgrbdEMhWYI_OsZAmOKcrf25AtQ6OwbsONH5h1SdXEdd7r53M-BH6isXnUipgy6TZFrqXZFy8ZrTE1Nah1wP9SH4TzaJLOkrRlXggoqjrPWk_7/" width="767" height="516" /></a>Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com1tag:blogger.com,1999:blog-7316696847298400232.post-20451434324478323742009-12-10T06:02:00.000-08:002009-12-18T06:18:46.592-08:00Schema and Data Compare Scripts in MS SQL<p>Hello All,</p> <p>I was searching for a tool which gives me the Schema and or data comparison for SQL Server, its really needed while we are updating staging or updating our live site. There may be lots of tool available on net but I found one tool which is part of <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&displaylang=en" target="_blank">Microsoft® Visual Studio Team System 2008 Database Edition GDR R2</a>.</p> <p>Team Edition provides lots of functionality, mainly we are using to write Test Case which is very useful for Test Driven Development.</p> <p>On top of this if you have Database edition then you can do lots of things with it. One of the feature is Schema and Data Compare. This blog post will walk you thru steps to compare data and schema.</p> <p><strong>Schema Comparison</strong></p> <p>1. Go to New Schema Comparison form Data menu</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCYd8lPGlaLXiCd1ua1OX65-aUKmBjwU6A_mzyObiyjxxW0SJagMPr8VyQM5FpuQ9uWsVMxfCR3zHfrtReAVJqlvcv5HEibJtT-3ukhPP_9cR_b6DExQXYlXHTFrNUuScGg3Qw4ZW3/" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCYd8lPGlaLXiCd1ua1OX65-aUKmBjwU6A_mzyObiyjxxW0SJagMPr8VyQM5FpuQ9uWsVMxfCR3zHfrtReAVJqlvcv5HEibJtT-3ukhPP_9cR_b6DExQXYlXHTFrNUuScGg3Qw4ZW3/[3].jpg" /></a></p> <p>2. Next select the two database, one is source and other is target</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJfaq57bbhobrfUQ8ZJUZcZirGWY6hToghWKnEXs8qsN0iZZDPiAdBCSw7SClRgv05vNGvlvI4xupIndgscEVM2acVX1fxb2uTrbiLtzWUC2iak-G2qfwhlbaXnCSB7UBPTrPahH1A/" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJfaq57bbhobrfUQ8ZJUZcZirGWY6hToghWKnEXs8qsN0iZZDPiAdBCSw7SClRgv05vNGvlvI4xupIndgscEVM2acVX1fxb2uTrbiLtzWUC2iak-G2qfwhlbaXnCSB7UBPTrPahH1A/" /></a>  <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvaCb8zCE9VtejQ2EE8uVL_eKpJykgN9neFsgdvOhcNv99mqTKW_K_03aOko0CCTHxhGkeekuBNA9GPVc7uE1p9oxg4r1zIhjwEtHbLO6NWR8jhOaswSUqjL2lHOBnSANNtB_vroMl/" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvaCb8zCE9VtejQ2EE8uVL_eKpJykgN9neFsgdvOhcNv99mqTKW_K_03aOko0CCTHxhGkeekuBNA9GPVc7uE1p9oxg4r1zIhjwEtHbLO6NWR8jhOaswSUqjL2lHOBnSANNtB_vroMl/" /></a> </p> <p>3. When press OK will give you the Schema Compare of all the objects including Tables, Views, Stored Procedures and many more.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9yums1677rMv1WEwgNQ2ewtxJHrOm-uLfOuCTrCtJkqchJi7G74RxwzyUMaHHkO1cg413InPY5vFHG8aLty-0d_mtSYxP6ZTudxRwk0Z1EUNzlTSZJxIYqXZO7W2FYOPI8FHVwtuU/s720/Four.jpg" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9yums1677rMv1WEwgNQ2ewtxJHrOm-uLfOuCTrCtJkqchJi7G74RxwzyUMaHHkO1cg413InPY5vFHG8aLty-0d_mtSYxP6ZTudxRwk0Z1EUNzlTSZJxIYqXZO7W2FYOPI8FHVwtuU/s720/Four.jpg" /></a> </p> <p>Here you can see the list of Objects and the Object Definitions windows</p> <p>4. In following image Table is expanded so you can see the changes in details on what table what action is held.</p> <p><a href="http://lh3.ggpht.com/_BE0RbE03Yi8/Syt_hgqlKlI/AAAAAAAAAT4/_46jtV4ThMA/s912/Five.jpg" target="_blank"><img src="http://lh3.ggpht.com/_BE0RbE03Yi8/Syt_hgqlKlI/AAAAAAAAAT4/_46jtV4ThMA/s912/Five.jpg" width="730" height="394" /></a> </p> <p>5. To see more in details select one of the updated row and you can see the definition in Object Definitions window; it will generate Create script and highlight the difference. There is also Schema Update Script which will have alter script of all the changes that is detected during Schema Compare.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYr2eWiB6kSL2o3u862RN7fmsGGTqzUUWiR_fLg8scdV-ddFEo8CPpeYu-GXljnzHK3vJgahv5NZAaQuzIRk1m2UtFo4UbxR_cTTRx15n145T7EUAaxmDc1lr4g_LnDkN7wgSedtR6/s912/Six.jpg" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYr2eWiB6kSL2o3u862RN7fmsGGTqzUUWiR_fLg8scdV-ddFEo8CPpeYu-GXljnzHK3vJgahv5NZAaQuzIRk1m2UtFo4UbxR_cTTRx15n145T7EUAaxmDc1lr4g_LnDkN7wgSedtR6/s912/Six.jpg" width="741" height="395" /></a> </p> <p>6. You can either copy the script or export to file or editor by using Export To Edition command on tool box.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNZ3CYx0K7Xal3w3qGAhvPDtY5pMR_tS1U9K8Vx3rdxW5D2Qv_7BJ2MDvlw7F3JArrFT2AgYvVSdPOt-5cjKoTYPX544tlyEVYfdKEqvc02vra9it6aMQkDT2ZikNlIJ0lMIB1c9FX/" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNZ3CYx0K7Xal3w3qGAhvPDtY5pMR_tS1U9K8Vx3rdxW5D2Qv_7BJ2MDvlw7F3JArrFT2AgYvVSdPOt-5cjKoTYPX544tlyEVYfdKEqvc02vra9it6aMQkDT2ZikNlIJ0lMIB1c9FX/" /></a> </p> <p>This was all about how to detect schema change, its very handy with lots of options. </p> <p><strong>Data Comparison</strong></p> <p>Now same way we have Data Comparison, which is use to compare data, it provides tons of details and script for insert/update and delete. The steps are pretty much starlight forward. I have listed the steps here.</p> <p>1. Click on New Data Comparison from Data menu</p> <p><a href="http://lh6.ggpht.com/_BE0RbE03Yi8/Syt_3HUKgJI/AAAAAAAAAUE/J42thun75YQ/Eight.jpg" target="_blank"><img src="http://lh6.ggpht.com/_BE0RbE03Yi8/Syt_3HUKgJI/AAAAAAAAAUE/J42thun75YQ/Eight.jpg" /></a> </p> <p>2. It will ask for Source and Target tables</p> <p><a href="http://lh4.ggpht.com/_BE0RbE03Yi8/Syt_3N6gyuI/AAAAAAAAAUI/SdnKPsLk4mE/Nine.jpg" target="_blank"><img src="http://lh4.ggpht.com/_BE0RbE03Yi8/Syt_3N6gyuI/AAAAAAAAAUI/SdnKPsLk4mE/Nine.jpg" /></a> </p> <p>3. On click of Finish, it will provide you all the information that is differ in between two database tables</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM9jppPa5TX5exZmG8ocZyBegQ5FZdcdsVkUTGcwR9EOVDEPGUY2AjRQEDfn3Y8rtNSStuuvvrRWMUS7y6vXP1hjhcq2DIAln6SCZjo8HAlc_yC6p2YOPYVWpfurpsZ__Dt-qXFFN5/" target="_blank"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM9jppPa5TX5exZmG8ocZyBegQ5FZdcdsVkUTGcwR9EOVDEPGUY2AjRQEDfn3Y8rtNSStuuvvrRWMUS7y6vXP1hjhcq2DIAln6SCZjo8HAlc_yC6p2YOPYVWpfurpsZ__Dt-qXFFN5/s912/Ten.jpg" width="821" height="435" /></a></p> <blockquote> <p>You can see here it shows 2 rows are only in source, means two rows are added to SB_mst_Group table. It also provides the what exact rows are added in middle section along with other options.</p> <p>In third last section which is Data Update Script; provides you the script for the action, here we have addition, so its provide the insert statements which we can run in UAT to get the date.</p> </blockquote> <p>I found it very useful and easy to generate required script in few mouse click!</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com4tag:blogger.com,1999:blog-7316696847298400232.post-35180909219189112342009-11-25T04:58:00.000-08:002009-12-11T05:04:36.882-08:00Consuming WCF service out of box<p>Hello All,</p> <p>I found one issue while consuming WCF service from out of box, There are lots of threads I found for '<em>The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.</em>' error, <em><a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.communicationobjectfaultedexception.aspx" target="_blank">CommunicationObjectFaultedException</a></em> exception thrown and '<em>The caller was not authenticated by the service.</em>'</p> <p>I spent lots of time in search, got bunch of solutions, some worked some does not, after doing lots of troubleshooting I got solution for my problem.</p> <p>My case was, a web application running on different box is trying to consume WCF service which is hosted on different box, but some how on production it was not working. It always throws <em>'<a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.communicationobjectfaultedexception.aspx" target="_blank">CommunicationObjectFaultedException</a>'</em>. Usually we are putting such calls in using blog, as its taking care of disposing object. But in case of WCF it may not work as per expected, the reason is; A <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.communicationobjectfaultedexception.aspx" target="_blank"><em>CommunicationObjectFaultedException</em></a> has been throws so you, the object is not yet initialized and you are using is trying to dispose method which again throw exception.</p> <p> <img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAgZFqTTupmhOnLJ0bYBdikcWtKSaN5ngLVb4qsFHXBUt6W8fVZFeIF4t2YBUabOi5TrsAl-Zu9c29_AMzB-D8R0CPjZQ7yUk2DwPaKWpXLAFiZ_O0zEUC1oepRmaFA9gQ-vgtwb1h/" /> </p> <p>This is because using implicitly call Dispose at the closing brace, which may throw an exception because your object is not yet initialized as its in the Faulted state. To over come this a simple solution, use try catch and call Abort. More reading on this click <a title="Avoiding Problems with the Using Statement" href="http://msdn.microsoft.com/en-us/library/aa355056.aspx" target="_blank">Avoiding Problems with the Using Statement</a>, good article form Microsoft including Sample application. During my search I found one good code delegate make you fell like you are using clause, but internally its handling such exception.</p> <div id="box"><pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">class</span> Util<br />{<br /> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> UsingWcf<T>(T client, Action<T> action)<br /> <span class="kwrd">where</span> T : System.ServiceModel.ICommunicationObject<br /> {<br /><br /> <span class="kwrd">try</span><br /> {<br /> action(client);<br /> client.Close();<br /> }<br /> <span class="kwrd">catch</span> (Exception)<br /> {<br /> client.Abort();<br /> <span class="kwrd">throw</span>;<br /> }<br /> }<br />}<br /><span class="kwrd">class</span> Program<br />{<br /> <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)<br /> {<br /><br /> Util.UsingWcf(<span class="kwrd">new</span> WcfClient(), c =><br /> {<br /><br /> });<br /><br /> <span class="rem">/*using (WcfClient wcfClient = new WcfClient())</span><br /><span class="rem"> {</span><br /><span class="rem"> ....</span><br /><span class="rem"> }// This will throw an error </span><br /><span class="rem"> */</span><br /> }<br />}</pre></div><br />So we have caught <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.communicationobjectfaultedexception.aspx" target="_blank"><em>CommunicationObjectFaultedException</em></a>, but still we are not able to make call to service method. Now you can see one new error '<em>The caller was not authenticated by the service'.</em> Cool we reach the service but its missing some credentials, as we are consuming service out of box.<br /><br />Typical configuration section looks like following<br /><br /><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5785DEJCtojGx8MoymFhRgWhynMLmnacMXPdVL1PmXirsO5LYUhPQcGihkFg_OdIqNdti4BZUMPom_ZwV5hCResRmmpVK2qxZYQ0ZJqoor2uIQ_Z4pRHxY7Yy8vhucCwZbXITaWOW/s640/WcfClient_Config.jpg" /><br /><br />Form error '<em>The caller was not authenticated by the service'</em> we can guess that we need some credentials to call method. You can see the configuration; it says clientCredentialsType="Windows" and security mode is Message, generally with wsHttpBinding these are the typical settings.<br /><br /><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5785DEJCtojGx8MoymFhRgWhynMLmnacMXPdVL1PmXirsO5LYUhPQcGihkFg_OdIqNdti4BZUMPom_ZwV5hCResRmmpVK2qxZYQ0ZJqoor2uIQ_Z4pRHxY7Yy8vhucCwZbXITaWOW/s640/WcfClient_Config.jpg" /><br /><br />As we are using Windows as credential type, we need to provide credentials to use WCF serverice out of box. Once this done you just need to pass user and password in ClientCredentials just like bellow<br /><br /><img src="http://lh5.ggpht.com/_BE0RbE03Yi8/SyJBULAOIMI/AAAAAAAAAPQ/kHJsKY-0haU/WcfClientCredentils.JPG" /> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com0tag:blogger.com,1999:blog-7316696847298400232.post-54174128255158303272009-11-21T09:36:00.000-08:002009-12-10T01:45:17.372-08:00Baroda Developers Conference<p>Hello All,</p> <p>Event  Baroda Developer Conference was held on Saturday, November 21, 2009 at Dr. I.G. Patel Seminar Hall Vadodara. </p> <p>Links: <a title="Baroda Mega Developers Conference" href="http://www.facebook.com/event.php?eid=162384666771" target="_blank">Baroda Mega Developers Conference</a>; <a title="Baroda Developers Conference [Dev-Con]" href="http://barodadevcon.eventbrite.com/" target="_blank">Baroda Developers Conference [Dev-Con]</a></p> <p>I recently gave presentation at a session titled as "<em>Features of C# 3.0</em>" followed by Probjots session "<em>Introducing LINQ" & "VS 2010 & .Net 4.0</em>" and "MOSS 2007" by Bhavin Gajjar. </p> <p>It was my first experience to give a presentation. There were students who were part of Microsoft Student Partner program with sound knowledge in Microsoft .Net Technology.</p> <p>Here are few snaps from conference.  </p> <p><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj39StLXXo9np39Keqs-Cvw0fDBLxhbwHPRrsSYKH3GVWrHhMyH_OFA9JoiEr2wM-0R5ZyqyEzM5PZR5yQORFna8G58PUkQrDgie9SnjI8QFSbYtMHxqL_ZkcHsmFmNcnUQNmYhPyZp/" /> </p> <p> <img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTV3Vig25T3SeC3is2nE2eHoR3kPPRL6S1P8pgSwdPgk88GGs6k7hG31HqMTt0Kq6TPq8ZMv4AsFsZCXpwDrP6KhvSRsMqIUH1s95AJ_F1IX0uC2hj0Vc5V2FLfFY-D4s8fz7-BjGy/" /></p> <p>[Attending one students' question on Partial Methods]</p> <p><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfLD66L-GnmgXObNwkSWFa2HoUAhF5yRqJMBFS8XPQ89ShMG1aFlF916uEKks8S0ahCPXKkVx8ktHvkeOE05xYQ6DH1LIVblVHymA4hYfNRVk52R1SiSbRR6odn5SVTZFp-WtyGOd7/" /> </p> <p>[Me with Probjot and students]</p> <p><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIpQvQI5CVnD-Gv-ConF5-5pCPF3Ng6_9eTvTlvaxCNf8VjAJNdW5NHa9NwpTXJhekFWhITi4s2EZZacfyk9nabYrl9zr08o2O-KlVtYvKft_KqUP_FwJ2klGc0tJ5nxw6qScqXRql/" /> </p> <p>[Attendees]</p> <p>I want to congratulate all the attendees for being part of such a knowledge sharing conference and taking active part in it.They came from different territories of all over India. I really appreciate their interest. Also I have demo project which I have used during my presentation to get this send me an <a href="mailto:bhadelia.imran@gmail.com" target="_blank">email</a>.</p> <p>I am very much thankful of <a href=" http://beyondrelational.com/blogs/jacob" target="_blank">Jacob Sebastian</a> who promoted me for this event and <a href="http://linkedin.com/in/prakhar" target="_blank">Prakher Mehta</a> who was the organizer and inviter of BUG [Baroda User Group]</p> Imranhttp://www.blogger.com/profile/06974863164594039994noreply@blogger.com7