locked
WCF Service RRS feed

  • Question

  • Hi,

    Can i Pass custom data from one wcf service to another wcf service other than service method parameter.

    Eg. I have to pass data from Client -> wcfService1 -> wcfService2. I Need to pass client ip address to Service 2. In Service1 we can get client ip address, but i need to pass this ip address to Service2.

    Is there any solution to pass this to Service2

    Thanks in Advance

    Umesh Manilal
    Monday, August 3, 2009 5:22 AM

Answers

  • Hi Steven / Prabi,

          Was able to solve the issue by giving the following code in BeforeSend event of SendActivity

    Client
    ----------------------     

    string

    myToken = "umesh";

     

    MessageHeader<String> mhg = new MessageHeader<string>(myToken);

     

    MessageHeader untyped = mhg.GetUntypedHeader("token", "ns");

     

    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);



      Server
    ---------------------------

    OperationContext

    context = OperationContext.Current;

    context.IncomingMessageHeaders.GetHeader<

    String>("token", "ns");

     

     


    Thanks Steven /Prabi for support and helping me to solve this issue.

    Regards,

    Umesh manilal

    • Marked as answer by Umesh Manilal Monday, August 10, 2009 1:00 PM
    Monday, August 10, 2009 1:00 PM

All replies

  • Hi,

    You can have keep one static class on the server in which you can set one variable for IP address from service1 and you can access this from service2. but remember one thing, after doing this both services will be dependant on this class that means you cannot deploy them seperately. 

    Check if this suits your requirements.

    Regards,
    Prabi

    I can be still better.
    Monday, August 3, 2009 5:32 AM
  • Hi,

           I think this workaround will fail if multiple client are accessing same service.


    Regards
    Umesh Manilal

    Monday, August 3, 2009 6:19 AM
  • hi,

    Then u can have key value collection in that static class in which u can add IP address from service1 and retriew from service2. 

    Just one question here, are u going to keep these services on the seperate machine or same machine?

    Regards,
    Prabi

    I can be still better.
    Tuesday, August 4, 2009 4:24 AM
  • Yes,WCF does not spport this, but you can implete it yourself.
    1)Static var,like the them desripbed.
    2)file,store the client id  into a file ,and another service read it from the file.
    3)DataBase.
    4)define a setter for the service B attribute.when service A get the IP,call the setter and set the IP value for Service B.
     Regards.


    Frank Xu Lei--谦卑若愚,好学若饥
    专注于.NET平台下分布式应用系统开发和企业应用系统集成
    Focus on Distributed Applications Development and EAI based on .NET
    欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
    欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
    欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum
    Tuesday, August 4, 2009 4:42 AM
  • Hi Umesh,

    Try addign a custom message header into your WCF request. You can use "OperationContextScope" class so that you
    can add custom header at WCF client side. e.g.

    =====================
        CalcSVC.CalcServiceClient client = new CalcSVC.CalcServiceClient();
          
                using (OperationContextScope opScope = new 
    OperationContextScope((IContextChannel)client.InnerChannel))
                {
    
                    OperationContext op = OperationContext.Current;
    
    //add a custom header
    //this is a typed soapheader, you can also directly use the MessageHeader type
    
                      SimpleCredentialsHeader credheader = new 
    SimpleCredentialsHeader();
                      credheader.Username = "steven"; credheader.Password = 
    "password";    
                      op.OutgoingMessageHeaders.Add(credheader);
    
                    string desc = client.GetDescription();
                    Console.WriteLine(desc);
                }
    ============================


    some other articles about adding custom WCF message header:


    http://blogs.microsoft.co.il/blogs/bursteg/archive/2006/04/23/141.aspx

    http://weblogs.asp.net/avnerk/archive/2006/04/26/Adding-custom-headers-to-every-WCF-call-_2D00_-a-solution.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 4, 2009 10:46 AM
  • Hi Prabi,

        for the time being i am using both the service in same machine, but can be installed in seperate machines.

    Regards

    Umesh Manilal

    Wednesday, August 5, 2009 11:30 AM
  • Hi Prabi,

    Does the custom soap header approach work for you? You can add additional info via header without modifying your main message body part.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, August 10, 2009 4:09 AM
  • Hi Steven,

        I am calling the service method from Windows Workflow using SendActivity. In my project i am adding service interface dll for invoking service method. So i am not be able to get the InnerChannel of the Service Method

    Regards,

    Umesh Manilal
    Monday, August 10, 2009 11:28 AM
  • Hi Steven / Prabi,

          Was able to solve the issue by giving the following code in BeforeSend event of SendActivity

    Client
    ----------------------     

    string

    myToken = "umesh";

     

    MessageHeader<String> mhg = new MessageHeader<string>(myToken);

     

    MessageHeader untyped = mhg.GetUntypedHeader("token", "ns");

     

    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);



      Server
    ---------------------------

    OperationContext

    context = OperationContext.Current;

    context.IncomingMessageHeaders.GetHeader<

    String>("token", "ns");

     

     


    Thanks Steven /Prabi for support and helping me to solve this issue.

    Regards,

    Umesh manilal

    • Marked as answer by Umesh Manilal Monday, August 10, 2009 1:00 PM
    Monday, August 10, 2009 1:00 PM