none
need help regarding OperationContextScope RRS feed

  • Question

  • here i have got a code where few area is not clear to me.

    using (new OperationContextScope(service.InnerChannel))
            {
                // login
                service.Login(userName, password, String.Empty, createPersistentCookie);
    
                // Get the response header
                var responseMessageProperty = (HttpResponseMessageProperty)
                    OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
    
                string encryptedCookie = responseMessageProperty.Headers.Get("Set-Cookie");
    
                // parse header to cookie object
                var cookieJar = new CookieContainer();
                cookieJar.SetCookies(new Uri("http://localhost:1062/"), encryptedCookie);
                Cookie cookie = cookieJar.GetCookies(new Uri("http://localhost:1062/"))[0];
    
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                if (null != ticket)
                {
                    //string[] roles = RoleManager.GetRolesFromString(ticket.UserData); 
                    HttpContext.Current.User = new GenericPrincipal(new FormsIdentity(ticket), null);
                    FormsAuthentication.SetAuthCookie(HttpContext.Current.User.Identity.Name, createPersistentCookie);
                }
            }

    i just do not understand what is OperationContextScope ? what it is doing in the above code.

    why OperationContextScope need service.InnerChannel ? what is the meaning of service.InnerChannel ?

    Thursday, May 8, 2014 2:07 PM

Answers

  • Hi,

    >>i just do not understand what is OperationContextScope ?

    If you are using callbacks or if you want to modify the message or headers then you need to use OperationContextScope .

    When you establish OperationContextScope then you can:
    1) Access and modify incoming and outgoing message headers and other properties.

    2) Access the runtime, including dispatchers, the host, channel, and extensions.

    3) Access other types of contexts, such as security, instance, and request contexts.

    4) Access the channel associated with the OperationContext object or (if the channel implements System.ServiceModel.Channels..::.ISession) the associated channel's session identifier.

    For more information, please try to refer to:
    #OperationContextScope:
    http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontextscope(v=vs.110).aspx .

    >>what it is doing in the above code.

    The following article has told what does the above code do, please try to check it:
    http://jonas.follesoe.no/2008/09/12/wcf-authentication-services-silverlight-and-smelly-cookies/ .

    >>why OperationContextScope need service.InnerChannel ? what is the meaning of service.InnerChannel ?

    The OperationContextScope class will create a scope a scope for a new OperationContext object using a specified IContextChannel object. An OperationContextScope with the .InnerChannel can be used in a Windows Communication Foundation (WCF) service or WCF client application.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 12, 2014 8:18 AM
    Moderator
  • can u give me small example for each like how to manipulate incomming & outgoing message with operationcontext ?

    how to manipulate runtime , dispatchers, the host, channel, and extensions.? thnx

    Hi,

    Please try to check the following article to help you get start.

    #WCF message headers with OperationContext :
    http://robbincremers.me/2011/12/29/wcf-message-headers-with-operationcontext-and-with-messageinspector-and-custom-service-behavior/ .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 15, 2014 2:06 AM
    Moderator

All replies

  • Hi,

    >>i just do not understand what is OperationContextScope ?

    If you are using callbacks or if you want to modify the message or headers then you need to use OperationContextScope .

    When you establish OperationContextScope then you can:
    1) Access and modify incoming and outgoing message headers and other properties.

    2) Access the runtime, including dispatchers, the host, channel, and extensions.

    3) Access other types of contexts, such as security, instance, and request contexts.

    4) Access the channel associated with the OperationContext object or (if the channel implements System.ServiceModel.Channels..::.ISession) the associated channel's session identifier.

    For more information, please try to refer to:
    #OperationContextScope:
    http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontextscope(v=vs.110).aspx .

    >>what it is doing in the above code.

    The following article has told what does the above code do, please try to check it:
    http://jonas.follesoe.no/2008/09/12/wcf-authentication-services-silverlight-and-smelly-cookies/ .

    >>why OperationContextScope need service.InnerChannel ? what is the meaning of service.InnerChannel ?

    The OperationContextScope class will create a scope a scope for a new OperationContext object using a specified IContextChannel object. An OperationContextScope with the .InnerChannel can be used in a Windows Communication Foundation (WCF) service or WCF client application.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, May 12, 2014 8:18 AM
    Moderator
  • thanks for reply. here u said OperationContextScope  is used to manipulate as follows

    1) Access and modify incoming and outgoing message headers and other properties.

    2) Access the runtime, including dispatchers, the host, channel, and extensions.

    3) Access other types of contexts, such as security, instance, and request contexts.

    can u give me small example for each like how to manipulate incomming & outgoing message with operationcontext ?

    how to manipulate runtime , dispatchers, the host, channel, and extensions.? thnx

    Monday, May 12, 2014 7:02 PM
  • can u give me small example for each like how to manipulate incomming & outgoing message with operationcontext ?

    how to manipulate runtime , dispatchers, the host, channel, and extensions.? thnx

    Hi,

    Please try to check the following article to help you get start.

    #WCF message headers with OperationContext :
    http://robbincremers.me/2011/12/29/wcf-message-headers-with-operationcontext-and-with-messageinspector-and-custom-service-behavior/ .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 15, 2014 2:06 AM
    Moderator