5
Answers

In wcf service. how detect incoming request operating syste

In wcf service.  how detect incoming request operating system like Android or IOS.
Answers (5)
0
Srikant Maruwada

Srikant Maruwada

NA 501 4.3k 7y
HTTP headers, request messages can be intercepted before they are sent to the server. This can be done by implementing the IClientMessageInspector.BeforeSendRequestmethod:
  1. /// <summary>  
  2. /// Representsa run-time behavior extension for a client endpoint.  
  3. /// </summary>  
  4. public class CustomEndpointBehavior : IEndpointBehavior  
  5. {  
  6. /// <summary>  
  7. /// Implements a modification or extension of the client across an endpoint.  
  8. /// </summary>  
  9. /// <param name="endpoint">The endpoint that is to be customized.</param>  
  10. /// <param name="clientRuntime">The client runtime to be customized.</param>  
  11. public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)  
  12. {  
  13. clientRuntime.ClientMessageInspectors.Add(new ClientMessageInspector());  
  14. }  
  15. /// <summary>  
  16. /// Implement to pass data at runtime to bindings to support custom behavior.  
  17. /// </summary>  
  18. /// <param name="endpoint">The endpoint to modify.</param>  
  19. /// <param name="bindingParameters">The objects that binding elements require to support the behavior.</param>  
  20. public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)  
  21. {  
  22. // Nothing special here  
  23. }  
  24.   
  25. /// <summary>  
  26. /// Implements a modification or extension of the service across an endpoint.  
  27. /// </summary>  
  28. /// <param name="endpoint">The endpoint that exposes the contract.</param>  
  29. /// <param name="endpointDispatcher">The endpoint dispatcher to be modified or extended.</param>  
  30. public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)  
  31. {  
  32. // Nothing special here  
  33. }  
  34.   
  35. /// <summary>  
  36. /// Implement to confirm that the endpoint meets some intended criteria.  
  37. /// </summary>  
  38. /// <param name="endpoint">The endpoint to validate.</param>  
  39. public void Validate(ServiceEndpoint endpoint)  
  40. {  
  41. // Nothing special here  
  42. }  
This interception is a behavior or an extension of WCF endpoints, so one more method needs to be implemented to apply that behavior to the endpoint, the IEndpointBehavior.ApplyClientBehavior method:
  1. /// <summary>  
  2. /// Represents a run-time behavior extension for a client endpoint.  
  3. /// </summary>  
  4. public class CustomEndpointBehavior : IEndpointBehavior  
  5. {  
  6. /// <summary>  
  7. /// Implements a modification or extension of the client across an endpoint.  
  8. /// </summary>  
  9. /// <param name="endpoint">The endpoint that is to be customized.</param>  
  10. /// <param name="clientRuntime">The client runtime to be customized.</param>  
  11. public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)  
  12. {  
  13. clientRuntime.ClientMessageInspectors.Add(new ClientMessageInspector());  
  14. }  
  15. /// <summary>  
  16. /// Implement to pass data at runtime to bindings to support custom behavior.  
  17. /// </summary>  
  18. /// <param name="endpoint">The endpoint to modify.</param>  
  19. /// <param name="bindingParameters">The objects that binding elements require to support the behavior.</param>  
  20. public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)  
  21. {  
  22. // Nothing special here  
  23. }  
  24. /// <summary>  
  25. /// Implements a modification or extension of the service across an endpoint.  
  26. /// </summary>  
  27. /// <param name="endpoint">The endpoint that exposes the contract.</param>  
  28. /// <param name="endpointDispatcher">The endpoint dispatcher to be modified or extended.</param>  
  29. public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)  
  30. {  
  31. // Nothing special here  
  32. }  
  33. /// <summary>  
  34. /// Implement to confirm that the endpoint meets some intended criteria.  
  35. /// </summary>  
  36. /// <param name="endpoint">The endpoint to validate.</param>  
  37. public void Validate(ServiceEndpoint endpoint)  
  38. {  
  39. // Nothing special here  
  40. }  
  41. }  
The last step is to add the new behavior to the WCF endpoint:
  1. Endpoint.EndpointBehaviors.Add(new CustomEndpointBehavior());  
0
Subhashkumar Yadav

Subhashkumar Yadav

NA 1k 7k 7y
Mangesh,
I want to check and log incoming request coming from which Device/os i.e  androids or IOS.
0
Mangesh Gaherwar

Mangesh Gaherwar

NA 4.1k 70.8k 7y
Subhash
 i doubt if we can get them if u have checked then its better u are sending the value from the client (i.e. androids or IOS) itself
 
 
0
Subhashkumar Yadav

Subhashkumar Yadav

NA 1k 7k 7y
I have checked no option showing for os detection. can you tell me where i will get OS details Like Android or IOS.
0
Mangesh Gaherwar

Mangesh Gaherwar

NA 4.1k 70.8k 7y
U cab check for the uaeragent of the request