cansik
cansik

Reputation: 2004

How to get the called address of a WCF Rest Request?

I have implemented a REST Webservice which returns (after an authentication via RFC 2617 HTTP Digest Authentication) an XML document with xlink's to the related resources.

Here's an example of a request:

http://172.32.42.53:8080/Service.svc/user/123

A result could look like this:

<?xml version="1.0" encoding="utf-8"?>
<UserList xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <User>
    <ID>2</ID>
    <UserName>CHI</UserName>
    <OutlineLink xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://demo:8080/Service.svc/Users/2/Outline/" cache="no"/>
    <SettingsLink xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://demo:8080/Service.svc/Users/2/Settings/" cache="no"/>
    <CatalogsLink xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://demo:8080/Service.svc/Users/2/Catalogs/" cache="no"/>
    <LastName>Test</LastName>
  </User>
</UserList>

So, the problem now is:

If the user calls the webservice via the IP address, the first handshake will be over the ip address and not the DNS name. So the authentication does only work if the second call (to the specified resource) will be over the IP address again. I tried it with following command:

OperationContext.Current.IncomingMessageProperties.Via.ToString();

But my webservice returns always the dns of the server and not the "called address".

Is there a possibility to get the called address? So I can dynamically return the called address (ip or dns). Would be great to get a solution. Relative URLs aren't allowed for xlinks.

Thanks for help!

Upvotes: 0

Views: 499

Answers (1)

Rajesh
Rajesh

Reputation: 7886

Can you try to retrieve the called address from the request's server variables? I guess your web service needs to be in asp.Net compatibility mode to access this. Something like "REMOTE_HOST", "HTTP_HOST", "SERVER_NAME", etc...

Check this link for list of server variables

Upvotes: 1

Related Questions