function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Doug SchmidtDoug Schmidt 

Is there a SOAP equivalent of RestRequest.remoteAddress?

My custom app would like to know the public IP address of the client making a custom SOAP web service call.

I see that the RestRequest (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_restrequest.htm#apex_methods_system_restrequest) class exposes both a remoteAddress and headers property.

I'm looking for something similar in a custom SOAP web service. Is there an equivalent?

So if my API wanted to send a different response if called from a well-known IP (for example, Google's DNS), I would expect the code to look something like this:
webservice static string MyCustomApi(MyRequest request)
{
    return (SoapContext.Request.remoteAddress == "8.8.8.8")
        ? "Hello Google DNS"
        : "Hello, someone other than Google";
}

Is that possible? I can't find any documentation that says it is possible from SOAP, only from REST, and that seems rather unfortunate.
Jason BealJason Beal
Is your web service anonymous, or does it require the client to log in?

If there is a login you could use the LoginHistory to find the IP used during the login. 
string ip = [select SourceIp from LoginHistory where UserId = :System.UserInfo.getUserId() order by LoginTime desc limit 1][0].sourceip;

 
Doug SchmidtDoug Schmidt
Unfortunately it is an anonymous webservice.