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

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



Answer this question

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

  • ProjectDev

    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



  • Pipz

    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.



  • Adam Miles

    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>


  • SQLme

    Hi jdang

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

    Thanks...


  • redshock

    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


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