zoukankan      html  css  js  c++  java
  • ProtocolBased Correlation in WF 4.0Context Exchange Correclation

    http://msdn.microsoft.com/en-us/library/ee358724.aspx 

    Question:does anyone know the  Context Exchange Correclation topic in msdn ? in this article . it took me a whole afternoon to read and test the code example , actually ,it always seems to be enough simple. but , finally . i have to say . i am fail and confused with this article . it drived me nuts. following exactly the steps with the article provides. writing the code . and debugging , testing .... it doesn't work . all this thing make me believe . maybe it is a bug of msdn ? 

    and the worst  of all is you can not find the example in which is attached with . that is known as the NetContextExchangeCorrelation sample.

    fortunately, i found another good article which has the same topic . from here.

    As a tester for correlation, I am sometimes asked to debug projects where people can’t get content-based correlation working. One of the common things that I like to ask is “Why are you using Content-based correlation”? Most of the time I’m met with a blank stare, or maybe the response “because that’s how this works, right Darren?”

    Content-based correlation isn’t the only form of correlation in WF 4.0, and in fact it’s definitely the more complex of the two major forms of correlation that we ship with. The other is Context Based Correlation. Like its content based brother, context correlation uses a piece of data in the message (a well known message header) to identify a message and correlate it to a specific instance of a workflow. Unlike Content correlation though, you don’t have to provide any message queries and in most cases you don’t even need to provide a correlation handle.

    Before I go into how Context Correlation works, let’s talk about the pros and cons. The idea with context correlation is that we are removing all of the work of setting up the correlation for you. Anytime that you are adding an ID to your message just for correlation purposes, you can probably just use context correlation and get the same results. Context correlation will not only set up the queries for you, but it will also generate unique data for each of your workflows, and it will store that data for you, meaning you can think about more complex problems, like what’s for lunch.

    Of course context correlation isn’t silver bullet, and in some situations it’s not possible to accomplish your task with context alone. First of all, if you don’t have complete control over what binding will be used, you won’t be able to use context correlation. In order to enable it you need to add a ContextBindingElement, if you can’t add that your binding, then you are going to need to use Content correlation. There is one other difference as well, a context correlation is always going to tie one client workflow with one service workflow, if you want to go beyond that then you need to go through alot of effort to grab the context from the channel, and most likely you would be better off with content based correlation. Because of the fact that there is just a tight coupling between the client/service once your client or service workflow completes the correlation is effectively terminated. Content correlation on the other hand is independent on the client, so you can have multiple client workflows, or maybe the same client workflow that connects multiple times. The point is that with context correlation you usually pair one client side workflow with one service side workflow, if that’s your situation, then great otherwise you should to stick with a content-based correlation.

    So, how does Context correlation work? I’ve attached an example workflow which uses context correlation. The workflow starts when a request for a new game is created (the workflow models a typical number guessing game). Anyways the first 3 message are below, the things to note are that the context exchange mechanism requires a request-reply (2-way) operation in order to initiate. Its fairly obvious why when you see how the exchange happens:

     

    Initial Request which activates the service workflow

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">

      <s:Header>

        <a:Action s:mustUnderstand="1">http://tempuri.org/GuessingGameService/StartNewGame</a:Action>

        <a:MessageID>urn:uuid:3bad75b4-5852-4473-8a9f-326899613804</a:MessageID>

        <a:ReplyTo>

          <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>

        </a:ReplyTo>

        <a:To s:mustUnderstand="1">http://localhost:42708/GuessingGameService.xamlx</a:To>

      </s:Header>

      <s:Body>

        <StartNewGame xmlns="http://tempuri.org/">

          <maxNumber>100</maxNumber>

        </StartNewGame>

      </s:Body>

    </s:Envelope>

     

    Response to activating request, send back the context ID

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">

      <s:Header>

        <a:Action s:mustUnderstand="1">http://tempuri.org/GuessingGameService/StartNewGameResponse</a:Action>

        <a:RelatesTo>urn:uuid:3bad75b4-5852-4473-8a9f-326899613804</a:RelatesTo>

        <Context xmlns="http://schemas.microsoft.com/ws/2006/05/context">

          <Property name="instanceId">52e6ca00-a33b-40b0-8ea3-8df9433ae894</Property>

        </Context>

       </s:Header>

      <s:Body>

        <StartNewGameResponse xmlns="http://tempuri.org/">

          <ActualNumber>14</ActualNumber>

        </StartNewGameResponse>

      </s:Body>

    </s:Envelope>

     

     

    Followup request which contains the context ID..

     

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">

      <s:Header>

        <a:Action s:mustUnderstand="1">http://tempuri.org/GuessingGameService/MakeGuess</a:Action>

        <a:MessageID>urn:uuid:f1e8d7bf-bb30-491d-aa52-8c06df2dc3f7</a:MessageID>

        <a:ReplyTo>

          <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>

        </a:ReplyTo>

        <Context xmlns="http://schemas.microsoft.com/ws/2006/05/context">

          <Property name="instanceId">52e6ca00-a33b-40b0-8ea3-8df9433ae894</Property>

        </Context>

        <a:To s:mustUnderstand="1">http://localhost:42708/GuessingGameService.xamlx</a:To>

      </s:Header>

      <s:Body>

        <MakeGuess xmlns="http://tempuri.org/">

          <PlayerGuess>50</PlayerGuess>

        </MakeGuess>

      </s:Body>

    </s:Envelope>

     

     Well, thanks for reading this. Look for more posts in the near future around correlation, and workflow services! 

    test project download here


    the service is simple enough which includes multiple pairs of receive and sendreply activity. you can not find any correlation setting info with it . and also the client is simple coding . just use a CorrectionScope to wrap all the thing for calling the service which includes multiple pairs of send and receivereply activitiy.

    the important point i want to mention here . it both client and service should bind the endpoint using WSHttpContextBinding. 
    anyone who also had the same problem which i mentioned firstly in this article .pls give me some comments or solution .  i will be appreciated for it .
  • 相关阅读:
    HDUOJ---------(1045)Fire Net
    HDUOJ----(1175)连连看
    HDUOJ-----(1072)Nightmare(bfs)
    deque容器的运用一点一点积累
    HDUOJ----(1016)Prime Ring Problem
    HDUOJ----Safecracker(1015)
    hduoj---Tempter of the Bone
    VC6.0设置注释快捷键
    nyoj------------找球号(一)
    set 容器 的全解(转)
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2555525.html
Copyright © 2011-2022 走看看