in

Community Blogs

Blogs of different SQL/Developers Community Members

This Blog

Syndication

DamirDobric

kolovoz 2008 - Posts

  • Mobility Day in Zagreb

    I would like to announce, that I will be at September 09. Zagreb at Mobility Day. My topic this time will be "Connecting Systems - Best practices". The session will have two parts. First part will be presented by me and the second one by Andreas Erben.
    This featured session will cover some advanced basics at the level 400. One could ask, how level 400 can be related to any kind of basics?
    This is true, but the basic thing will be well known Hello World Calculator Service, with more issues than you can imagine.
    Advanced part of the session will be the solution, which will show how to design the application able to survive bad network connection and how to wait for recovery from offline to online mode.

    ... and all this by using of retrying binding element which does not exist and by using of asynchronous delegates which are not supported on the mobile stack...

    If you are interested feel invited.

    Here is preliminary agenda:

    image

  • FormsAuthentication and DangerousUrl Issue

    It is often a case that complex ASP.NET applications make usage of request query strings.
    For example it can happen that same page is opened with the request query like this one:

    http://localhost:7000/YourApp/Login.aspx?ReturnUrl=%2fYourApp%2fDefault.aspx%3fControledStart%3dtrue%26NewWindow%3dPleaseNotOpenInNewWindow%26OpenFromSakibovePlatice%3d%7e%2fProcessesID%2cakrcici%7C101002%7C101003

    If FormsAuthentication is used, the user will be redirected to the login page after the login session expires. That is the case when the user open such page (with URL shown above) and remains inactive for a while. On next user's action, the application will redirect the user to login page and fail with following exception:

    "The return URL specified for request redirection is invalid."

    This exception is thrown when following statement is executed:

    FormsAuthentication.RedirectFromLoginPage(username, true);

    Solution

    Internally this exception is thrown in the method called GetReturnUrl(bool useDefaultIfAbsent) (invoked from RedirectFromLoginPage), when the redirection URL seems to be dangerous?!

    Hmm, what this could mean?

    Somewhere deep in the ASP.NET there is a method which decides which request is the good one and which is the evil one.
    This is the original code, which I'm not going to comment (self explaining).
    image

    Now, because we know who is evil or who it could be, there is a very simple workaround shown in the next example:

    image

    Before we enforce redirection, let's check the evil state by calling IsDangerousUrl. Note that this method is an internal one. To call it, just implement your own clone. If  the request (QueryString["ReturnUrl"]) is the evil one, just do redirect to default location as shown in else clause.


    Hope this helps...

    Posted kol 29 2008, 10:21 by anonymous
    Filed under:
  • Happy T-Mobile UMTS Express Card user

    Few weeks ago DAENET purchased T-Mobile Express UMTS cards for developers. After weeks of testing I'm not really able to express my experiences. The good new is, that the card is in general working. The bad news is that the card is not very stable. Hmmm?!
    I know, you are probably like "what that this really mean"? This is exactly how I feel all this time.

    More precisely here is the list of things I do not like (All related to HUAWEI Mobile Connect Express - Model E870):

    1. You have the card which works with 7.4MBit/Sec.
    2. You have a card which will probably not work when you need it.
    3. Web and Walk (software installed for the card) is not stable at all. Sometimes the card is initialized, but the software does not recognize it. Sometimes the software shows the signal, but the card is not initialized.
    4. The driver just stops working after 20-30 minutes in connected state.
    5. When the card stops working there is no way to re-initialize it.
    6. Few times I had event Blue Screen
    7. Sometimes when the card stop working the whole network stack stops working. Only reboot helps.
    8. The documentation and support in Internet does not exists according to IT standard. Try to enter the name of the card in Google and pray for results.
    9. Setup installs too many modems, drivers etc. There is even one service. Hey Desktop App architects, please do not design desktop application which require windows service as a part of your application. Today, even my PDF reader installs some service. Web and Walk uses AutoUpdateSrvService. Anybody heard something about lick once?
    10. Last but not least, I'm also happy Vista user. :( T-Mobil support says that either my laptop or Microsoft is responsible for everything.
    Unfortunately, I know at least few more people with same or similar issues.

    Here is my Feedback to happy community:

    If the card does not work do following for resurrection purposes:

    1. Uninstall the card
    2. Uninstall Web and Walk (remove additionally AutoUpdateSrv.exe)
    3. Install the card
    4. Set "Do not use PIN" option by using of the card.
    5. Use "Mobile Internet" remote access connection to activate the card. (Do not use any other software)

     

    1. Uninstall the card:
    Here is what well designed software has to be removed from the system:

    - Communication Center
    - GTHSDPA
    - HotSpot Manager
    - Huawei  (possible more than one application)
    - Mobile Broadband Drivers
    - Novatel  (possible more than one application)
    - Option (possible more than one application)
    - Odyssey
    - Sony Ericsson GCXX
    - T-Mobile web'n'walk Manager
    - VPN Client (related to HotSpot Manager)
    - web'n'walk Manager  (possible more than one manager application)

    2. Uninstall Web and Walk

    Go to software Programs and remove it.
    If the service is installed go to registry, search for AutoUpdateSrvService.When found stop the service locate the location of executable, remove it and remove all registry hive.

    If the uninstll fails goto registry and remove at least following keys:

    - Bytemobile
    - T-Mobile  
    - C:\Program Files\InstallShield Installation Information\{A899DA1F-D626-401C-8651-F2921E3B4CB3}

    3. Install the card

    This is very important, because issue here is to find the most recent installation. Google? Forget it.
    This is the ultimate location: ftp://tmcc.t-mobile.de.
    Hi Google, please be so nice and scan this, so all people in the world can use it now.

    4. Set "Do not use PIN"


    Insert the card in you mobile phone (i.E.windows mobile), open communication manager and unselect "Use PIN". In German: "PIN zur Benutzung des Telefons notwendig".

    5. Use "Mobile Internet" remote access connection

    Use only this to activate the card. (Do not use any other software). This can be used, because PIN is no more required.
    image

    Just right-mouse click on the icon "Mobil Internet", choose Connect and wait for a while

    My salutation for all housewives, who run into this problem.

  • SvcUtil error CS0102 and Service Modleing

    While generating proxy classes by SVCUTIL you may get following error:

    "error CS0102: The type 'ConsoleApplication1.ServiceReference1.SomeType already contains a definition for 'SomePropety'."

    Problem Description

    This error occurs, because NETSVCUTIL has created a type SomeType twice. If you open generated classes in references.cs you will see that following code exists twice (with few differences).

    public partial class SomeType : object, System.Runtime.Serialization.IExtensibleDataObject,
    System.ComponentModel.INotifyPropertyChanged
    {
      
    [System.NonSerializedAttribute()]
      
    private System.Runtime.Serialization.ExtensionDataObject someProperty;

       [System.Runtime.Serialization.OptionalFieldAttribute()]
      
    private string SomeProperty;

    }

    Mostly I get this error when the contract has been generated by ServiceFactory modeling edition. For example following model shows property named "Credentials", which is of type DataContract type SomeType.

    image

    If you click now on the shape LogInReq in the right bottom corner there is a property grid, which describes request properties.
    image
    If the request message (LogInReq shape) has one property only, the property "Is Wrapped" is by default set on FALSE. When this proeprty is set on on FALSE, you will get the error described above.

    Solution


    To solve a problem set property "Is Wrapped" on TRUE as shown at the picture above.

  • Creating Default Bindings on Compact Framework

    For creating of service proxies on Compact Framework (Mobile), which are WCF capable, the tool NetCfSvcUtil should be used.
    This tool is a part of .NET Compact Framework Power Toys 3.5. Note that WCF-CF edition is very small subset of WCF and it does not support everything. However on the basic level you will probably feel that almost everything is supported. This is fine.
    The biggest difference between these two builds is how they are build internally. And that is relevant at least when you decide to build some customization, which extends the compact framework stack.

    In general the NetCfSvcUtil build proxy, which use hard coded binding, but it has constructors which allows you to slightly modify default bindings.

    In general CF provides build in support for WS-I standard (basicHttpBinding) . If HTTP is used the binding looks like:

    image

    In a case of HTTPS the binding looks like shown below:
    image

    Please note marked differences.

  • The future of .NET Reflector

    Red Gate announced today that, under a new agreement, it will be responsible for the future development of .NET Reflector, the popular tool authored by Lutz Roeder. Red Gate will continue to offer the tool for free to the community.
    More about this: more about the future of .NET Reflector.

    Other interesting and related tools: http://www.hanselman.com/blog/ScottHanselmans2007UltimateDeveloperAndPowerUsersToolListForWindows.aspx

  • AJAX callbacks and Forms authentication

    When implementing ASP.NET applications which make usage of AJAX and Windows Forms Authentication, there are few critical issues you have to be aware of. in this post you can find few very interesting information related to AJAX and FormsAuthentication.

    Problem Description

    Assume there is an ASP.NET application which use Windows Forms authentication and has a page called WebFormSessionTest.Aspx. Additionally the application is configured to use FormsAuthentication when user requests this page. This is a common scenario based on forms authentication in ASP.NET.

    To configure application like this we would usually change web.config as shown below:

    <authentication mode="Forms">
     <forms name=".MYCOOKIE" loginUrl="Login.aspx" protection="All" timeout="15" path="/" />
    </authentication>

    Please note the attribute timeout="15" in this example. This value defines the validity time the token (cookie), which is internally created after successfully login. It means, the user will be required to login again if the user has no taken any action for more than 15 minutes. Forcing the user to take a logon again means "redirecting of user to "Login.aspx" page (defined by attribute 'loginUrl').
    Assuming that this is well known scenario, I'm not going to describe it in more detail.

    Now, imagine the page WebFormSessionTest.Aspx is designed to operate with AJAX callbacks. In other words this means the page implement interface ICallbackEventHandler.

    The critical issue, which I would like to describe begins at the moment when the user initiate AJAX callback, which should be handled by page WebFormSessionTest.Aspx. For example, the AJAX callback is initiated on press of some button B in the browser. As long the windows forms security token is valid all will work fine. However, if the user was inactive for a while (e.g.: 17 minutes) the token will expire and next request should be redirected to Login.aspx. Unfortunately, this does not work. At least not the way you could make any usage of it.

    When the AJAX request (callback) is received  by the ASP.NET server, the FormsAuthentication runtime finds out that the token is expired (actually the cookie '.MYCOOKIE' has expired) and redirects the request to the login page. This is fine, but after the Login.aspx page is rendered, usually the browser should show it to the user. Unfortunately this does not happen. Instead the user will not get any message, after pressing on button B. It means, user press button B and nothing happens. No any action, no any error, just nothing.

    "Why it does happen nothing?"

    The answer is very simple. When the JavaScript creates an AJAX request it expect to receive a stream, which contains some result. If the request has been successfully handled the result looks like:

         72|/wEWBQLOhofbCwKzmbmVDAK/7+btDAL0z6nBDAK/797tDBiuyu1InxdK8K0lSm1Dy9K0Jp5+ok

    This string is consisted as :
              Lenght(EventValidationValue) | EventValidationValue + Result

    In our case length is 72 and value is '/wEWBQLOhofbCwKzmbmVDAK..p5'. The 'ok' on the right side is returning AJAX  message. This is what is expected. Now, imagine what happen when instead of this text the HTML code of the login page is returned. The JavaScript AJAX runtime does not know what to do with retrieved HTML code and unfortunately, just ignores it.

    As result of this behavior AJAX will no more work in the application, as long some postback is initiated.

    Solution

    After some experimenting, fiddlering and reflectoring the solution looks like:

    1. Check in Global.ASAX.cs if the request is none-authenticated AJAX request. (Assuming ScriptManage.AuthenticationService is not used).
    2. If it is not just proceed.
    3. If it is none-authenticated AJAX callback, enforce redirecting to login page by appending some additional parameter.
    4. The Login.aspx page checks for additional parameter. If found the page will know that is is in callback context. Note that AJAX-callback has to be checked in Global.Asax.cs, because Login page is always invoked by redirect even if previous request has been AJAX callback.
    5. If the Login page is called within AJAX callback (additional parameter is contained in request) we send the browser expected AJAX stream instead of rendered Login.aspx html. In this stream we append some marker, which indicates that the tokens has been expired.
    6. Adopt AJAX java script handler function to be able to catch this information.

    Putting all together:

    GlobalAsax.cs: (Steps 1, 2 and 3):

    Here is the code to be appended in the Global.Asax.cs:

     image

    Login.cs (Steps 4 and 5):
    Here is the code to be appended in the Login.cs:

    image 

    The string returned here can be parsed by java script handler as a valid response. Response.End() ensures that Login.ascx HTML is not rendered.

    Java Script handler changes (Step 6)
    Following JAVA script is used to create request (AJAX callback) and to handle failed authentication. The function go()
    is called when the user presses the button B. After the request has been successfully processed by server handler the
    function onSuccess is called. If the argument equals "authenticationfailed" teh response has been created by Login.cs and it menas
    that the user is no more logged in.

    image

    Related article: http://developers.de/blogs/damir_dobric/archive/2006/10/09/939.aspx.

  • Windows Server 2008 blocks DTC

    Typical distributed application will have some kind of server/service and some database. For example, imagine there is an ASP.NET based application which has SQL Server as back-end. Although  the application works fine and all tests has passed successfully, you may figure out that the same app does not work on Windows Server 2008 machine.
    In a case of Web Application, which tries to perform some transaction (even very simple one) the user will have to wait in front of his/her browser until the request timeout is reached. While user is awaiting without of any knowledge what is going on behind the stage, the SQL Server in back-end block running transaction.

    Following picture shows, that the SQL Server is running in a transaction.

    image As As you can see process 51 has opened transaction. The bad thing is that Windows Server 2008 by default blocks Distributed Transaction Coordinator and transaction will never end.
    While SQL tries to ends the transaction (commit or rollback) the browser request will time out. After some time the transaction running will time-out too and the process 51 will become free. It means the SQL batch which caused the transaction will be canceled.

    To solve this problem you can take typical developer approach and stop the firewall. Or you should take the admin approach  (which is the right one) and enable required DTC rules.
    Following picture show three Win. Srv. 2008 firewall rules, which will allow DTC protocol when enabled.
    image

  • VS2008 SP1 Release and more

    After the release of SQL Server 2008 last week the final SP1 release of the following products is online too:

    · Team Foundation Server 2008 SP1 (133mb | For more information see TFS Installation Guide)

    · .NET Framework 3.5 SP1 (full 231mb)

    · Visual Studio 2008 SP1 (full iso (831mb) | bootstrapper exe |For more information go to readme)

    You can read more about what’s in the TFS SP1 release on MSDN.

    ·  If you previously installed a Visual Studio 2008 Hotfix, you must run the Hotfix Cleanup Utility before installing Visual Studio 2008 SP1. For more information, see Visual Studio 2008 Hotfix Cleanup Utility for Installing Visual Studio 2008 SP1.

    ·  If you have multiple Visual Studio products installed, you must upgrade all of them to SP1.

    ·  Prior to installation, you should carefully review the included readme file to be aware of any known issues with this release.

  • Workflow Service Host error

    When self-hosting the workflow service, for example in one console application, you may get following error:

    "Service behavior WorkflowServiceBehavior requires that the binding associated with endpoint BasicHttpBinding_IMyContract listening on http://localhost:8000/wfservice supports the context protocol, because the contract associated with this endpoint may require a session. Currently configured binding for this endpoint does not support the context protocol. Please modify the binding to add support for the context protocol or modify the SessionMode on the contract to NotAllowed."

    Note that some words in the error text above are related to my service and not to your one. That means that your error message will look probably slightly different.

    This error occurs when the used binding is not of expected type. In my example I used basicHttpBinding to host the workflow service. To solve the problem use a workflow specific binding *ContextBinding. For example basicHttpContextBinding.
    In general, when using workflow services following bindings are supported:

    BasicHttpContextBinding,
    WsHttpCOntextBinding and
    NetTcpContextBinding

    Posted kol 10 2008, 12:42 by anonymous
    Filed under: ,
  • Entity Framework compiling error

    Error    67    Error 3026: Problem in Mapping Fragment(s) starting at line(s) (982, 1103, 1112, 1121, 1129): Data loss or key constraint violation is possible in table TAggregationEvent.
    The following C-side state is not preserved upon retrieving persisted data from the store. An Entity instance e with Key (k) such that:
      ((k) plays role 'TAggregationEvent' in Association Set 'FK_TAggregationEvent_TBusinessLocation1' AND ((k) does NOT play role 'TAggregationEvent' in Association Set 'FK_TAggregationEvent_TBusinessLocation' OR (k) is NOT in 'TAggregationEvent' Entity Set OR (k) does NOT play role 'TAggregationEvent' in Association Set 'FK_TAggregationEvent_TEPCISEvent'))
        D:\Tfs\hyperion\DaenetProjects\RFID\Daenet.Epcis\Daenet.EpcisService\EntityModel.edmx    1113    11    Daenet.EpcisService

     

    Error    68    Error 3012: Problem in Mapping Fragment(s) starting at line(s) (982, 1103, 1112, 1121, 1129): Data loss is possible in FK_TAggregationEvent_TBusinessLocation1.TBusinessLocation.ID.
    The following C-side state is not preserved upon retrieving persisted data from the store. An Entity instance e with Key (k) such that:
      (e.TBusinessLocation.ID is not NULL AND ((k) does NOT play role 'TAggregationEvent' in Association Set 'FK_TAggregationEvent_TBusinessLocation' OR (k) is NOT in 'TAggregationEvent' Entity Set OR (k) does NOT play role 'TAggregationEvent' in Association Set 'FK_TAggregationEvent_TEPCISEvent') AND (k) plays role 'TAggregationEvent' in Association Set 'FK_TAggregationEvent_TBusinessLocation1')
        D:\Tfs\hyperion\DaenetProjects\RFID\Daenet.Epcis\Daenet.EpcisService\EntityModel.edmx    1104    11    Daenet.EpcisService

     

    Error    69    'EpcisDbModel.TAggregationEvent' does not contain a definition for 'BusinessLocationID' and no extension method 'BusinessLocationID' accepting a first argument of type 'EpcisDbModel.TAggregationEvent' could be found (are you missing a using directive or an assembly reference?)    D:\Tfs\hyperion\DaenetProjects\RFID\Daenet.Epcis\Daenet.EpcisService\EpcisService.cs    35    24    Daenet.EpcisService

     

     

    image

    Posted kol 10 2008, 12:40 by anonymous
    Filed under:
  • FakeGPS Installation Problem

    The Windows Mobile 6 SDK ships with a utility called FakeGPS that uses text files containing GPS to simulate the functionality of a GPS receiver. However if you try to install the FakeGps on the none-English system you will encounter following error:

    "No NMEA files, bla, bla".

    The problem is that installation program (CAB) installs the  tool on path %CE1% which is for example on German system "\Programme". Unfortinatelly the FakeGps program itself read raw data files (dixies.txt - and fakegpsdata.txt) from hard coded location \Program Files.

    To solve the problem make a folder \Program Files\FakeGPS\GPSFiles and copy all content of \Programe\FakeGPS\GPSFiles to that folder. Note that depending on your language word programe will be different.

    image

  • DataContractSerializer in Silverlight

    Microsoft has announced that DataContractserializer in version net35 sp1 will no more require class attributes DataContract and DataMember (finally).
    However, it is intersting that DataContractSerializer implementation in Silverlight already does not require [DataContract] and [DataMember] attributes on classes, which have to be serialized.

    :)

  • DataContractSerializer and ObservableCollection-s

    When using Silverlight, you may want to deserialize some data. Because XmlSerializer is not supported, you could peek DataContractSerializer (system.runtime.serialization.dll). In some specific scenario I had an observable list, which contains elements of some custom type named ServiceInfo.
    Unfortunately, if you use the common serialization code shown below to serialize the (observable) list, following exception will be thrown:

    image

    Type 'ServiceInfo' with data contract name 'ServiceInfo:http://schemas.datacontract.org/2004/07/...' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

    To fix this problem the underlying type used as list element has to be added as known type. Following code shows how to do that:

    image

  • List<object> performance

    Few days ago run into requirement to store about 500.000 objects in the List<object>. To store that amount of data in the list is not an issue.

    list.Find(item => item.Arg1 == arg1 && item.Arg2== arg2 && item.Arg3 ==arg3 && item.arg4 == arg4);

    While reading the line above, try to ask yourself, how much time your application will need to find a specific element defined by scalars { arg1, arg2, arg3, arg4 }?

    To measure this I performed two different kind of calculations on processor: x64 Family 6 Model 15 Stepping 10 GenuineIntel ~2400 Mhz

    First calculation one was the very simple average value, which resulted in 12 milliseconds. I learned at the university that the time is relative. I agree, but in information technology I experienced that the time is subjective too. So, 12 ms is pretty fast for half million of entries.

    However if you search for entries in the list which are on the beginning of the list you will notice that the processor performs much better. Your program will not need even one second to lookup entries  on the beginning of the list. Unfortunately, to lookup entries on the end of the list the program will need about 30 milliseconds.

    So I decided to calculate average time depending on the position in the list. For this experiment, I linearly sampled 10000 entries from the list of 500000 entries. The I created a kind of window of 100 samples and moved it over to whole interval. The result was average time for first 100 entries, then second hundred entries etc.

    Here is the diagram which shows results for all interval:

     image

    Conclusion:
    Without of performing exact analytical result, statistically it seems that the calculation time for looking up entries in the list linearly increases by moving to the end of the list. On the beginning of the list you can expect that looking up takes less than 1 ms. By entries on the position over 400.000 the time for looking is takes 25-30 ms. This is just to give you a feeling.

Copyright of SQL/Developers Community
Powered by Community Server (Commercial Edition), by Telligent Systems