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..
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.