We currently have a custom apex soap webservice which is called by an external dotnet application. The dotnet application uses the login method to login and then it tries to call the custom apex webservice using a hard coded string like https://cs15.salesforce.com/services/Soap/class/wsxxx. The problem is that we do not want the client application to hardcode the custom apex endpoints and I want to know how to avoid this hardcoding? The dotnet code currently calls the login and it gets the loginresult. Loginresult has a server url which has the entire schema and we need to point to a specific apex class service. He tried to set the server url but it returns an invalid session. So how do we avoid this hardcoded url string for custom apex webservices? Any sample code would help..

1 Answer 1


You need to hard code the path but not the server, most languages these days have URI classes that make putting the require URL together pretty easy, e.g.

// build a URL object for the regular server URL
URL serverUrl = new URL(loginResult.getServerUrl());

// build a new URL thats relative to serverUrl, as the path start with / this'll replace the whole path part of the url
URL apexUrl = new URL(serverUrl, "/services/Soap/class/wsxxx");

e.g. if serverUrl was https://na1.salesforce.com/services/Soap/u/29.0 then apexUrl will end up being https://na1.salesforce.com/services/Soap/class/wsxxx which is what you want.

The sample is based on Java, but I'm sure .NET has a similar class available.

  • Thanks for your reply. Since this is a soap based call, we do not need an end point to call the custom apex webservice. Is that right? Oct 30, 2013 at 2:39
  • Not sure what you're asking.
    – superfell
    Oct 30, 2013 at 2:41
  • Always login to login.salesforce.com for normal accounts, test.salesforce.com for sandboxes, and prerel.salesforce.com (I think) for pre-releases. When logging in, you'll get a direct reference to the server you're supposed to use (e.g. via the serverUrl parameter in the response). Best practices dictate that you shouldn't try to hardcode login urls, because instances can and do change.
    – sfdcfox
    Oct 30, 2013 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.