Find the source that fired a query via WCF from client RRS feed

  • Question

  • hi;

    I have a remote sql that hosted with WCF ,the remote sql give query from application or another sql via WCF

    my problem is ,how can I find the source that fired a query , When I trace the remote sql with below code the hostname field always return remote sql name (not client name)

    SELECT hostname from sys.dm_exec_sessions


    Wednesday, October 31, 2018 7:33 AM

All replies

  • Hi Aly14,

    According to your description, I am not clear about your requirement and project structure, would you mind telling me more details about your remote SQL, and how does it integrate with WCF? Or, it means that WCF work with database to enable client to CRUD the database? and you want to return the hostname (WCF server) via query?

    Best Regards


    Wednesday, October 31, 2018 2:02 PM
  • my sceneraio like below ;

    its working fine , I just catch to client's information from application or local sql in remote sql

    Friday, November 2, 2018 12:01 PM
  • Hi,

    Please try these code snippets.

    select @@SERVERNAME,SERVERPROPERTY('MachineName')

    Best Regards


    Wednesday, November 7, 2018 9:59 AM
  • I tried it , it's return Wcf server informations , not client.
    Wednesday, November 7, 2018 12:28 PM
  • Do you mean these SQL statements are sent by the client to the WCF server and then executed by the server database, and now you want to return the client information? I don't think it's related to SQL, we can return client information through WCF, we use the OperationContext object in the server method to return client port and iP information.
    I have made a demo, wish it is useful to you.

     public class MyService : IService
            public string GetClientInformation()
                OperationContext oc = OperationContext.Current;
                MessageProperties properties = oc.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                return endpoint.Address + ":" + endpoint.Port.ToString();


    Best Regards


    Thursday, November 8, 2018 3:19 AM
  • hi , I have 3 questions * its possible to return hostname or another thing instead of ip due to the ip isn't static * how can i know to call wcf service either application or sql
    Thursday, November 8, 2018 7:21 AM
  • Hi Aly14,

    Sorry for my poor English,please describe your question by details and clear content.

    >>how can I know to call wcf service either application or sql

    You could check the method you are able to invoke in the WSDL file. Such as http://localhost:90/Service1.svc?singleWsdl

    You could also know how to call WCF service by adding service reference. When you generate the client proxy class, you would find the method you can call in the service contract.


    Best Regards


    Monday, November 12, 2018 2:38 AM
  • I already able to call wcf from both But how can I know the request is coming either sql or application.

    you can get informatiton about my structure that I posted in above Picture.

    Monday, November 12, 2018 7:37 AM