none
How to get the name of client machine inside OperationContext Object?

    Question

  • Hi Everyone, 

    Does anyone know where to get the name of client machine inside OperationContext.Current object? I try to use OperationContext.Current.IncomingMessageHeaders.From property but it’s always null.

     

    Regards,

    Jdang

     

    Tuesday, January 30, 2007 9:13 PM

Answers

  • Hello Jdang,

    The NetTcpBinding wraps a TCP socket as a channel and sockets don't have any built-in feature for for providing the sender's machine-name. In other words, it isn't povided by the underlying transport so we don't have a way to surface it to you.

    Do you have the option of modifying your contract so it includes the client's machine-name as one of the parameters? Alternately, you could add a message-inspector that adds the machine-name as a custom header that you then extract in your service.

    Regards,
    David

    Wednesday, January 31, 2007 8:59 PM
  • David,

    Thanks for your time. Yes, I have to use MessageInspector to do this by adding my custom object into MessageHeaders collection to carry my extra data from client to the server. A little work without any book or documentation but it works now.

    Regards,

    JDang

    Thursday, February 1, 2007 2:50 PM

All replies

  • The From header isn't always sent. What binding are you using? What does your contract look like?

    Also, keep in mind that the orginal sender of a message can't always be determined. WIth transports like MSMQ, I can determine who sent the message (signature, other properties), but I can't determine what machine the user sent things from. It is also possible to fill in the From header with bogus data.

    Wednesday, January 31, 2007 12:59 AM
  • Hi Scott,

     

    I am using NetTcp bindding and here is my App.cofig file. Do I need to add something into my App.config file in order to see client's machine name?

     

    Regards,

     

    Jdang

     

    <system.serviceModel>

        <services >

          <service name="MyCompany.Services.CustomerService"  behaviorConfiguration="serviceBehavior"   >

            <host>

              <baseAddresses>          

                <add baseAddress="net.tcp://localhost:8000" />                     

              </baseAddresses>

            </host>

            <endpoint address="CustomerService" 

                      contract="MyCompany.Contracts.ICustomerService"

                      binding="netTcpBinding"  />

     

          </service>

        </services>

        

        <behaviors>

          <serviceBehaviors>

            <behavior name="serviceBehavior">

              <serviceMetadata httpGetEnabled="false"/>          

            </behavior>       

          </serviceBehaviors>     

        </behaviors> 

      </system.serviceModel>

    Wednesday, January 31, 2007 1:38 PM
  • Hello Jdang,

    The NetTcpBinding wraps a TCP socket as a channel and sockets don't have any built-in feature for for providing the sender's machine-name. In other words, it isn't povided by the underlying transport so we don't have a way to surface it to you.

    Do you have the option of modifying your contract so it includes the client's machine-name as one of the parameters? Alternately, you could add a message-inspector that adds the machine-name as a custom header that you then extract in your service.

    Regards,
    David

    Wednesday, January 31, 2007 8:59 PM
  • David,

    Thanks for your time. Yes, I have to use MessageInspector to do this by adding my custom object into MessageHeaders collection to carry my extra data from client to the server. A little work without any book or documentation but it works now.

    Regards,

    JDang

    Thursday, February 1, 2007 2:50 PM
  • Hi jdang

     

    Could you post your solution here? I've the same problem, but with a basicHttp-Binding

     

    Thanks...

    Thursday, May 31, 2007 1:46 PM