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
ArcosArcos 

ServerURL returned by the login WSDL is wrong

Hi,

I am trying to implement the integration of an external system with Salesforce and have exposed a WS using an apex class for this purpose. In order to access the WS Salesforce documentation (https://help.salesforce.com/apex/HTViewSolution?urlname=Updating-Hard-Coded-References-FAQ&language=en_US) states I should first consume a login WS (enterprise or partner). The response should contain a ServerURL and a Session ID. That ServerURL should be set as the target endpoint for a subsequent call to my WS. 

The issue is when I set the targent endpoint as the URL for my WS call in SOAP UI I am getting the following response:
No operation available for request {http://soap.sforce.com/schemas/class/ICL_GatewaySAP}QueryRequest

The login WSDL URL: 
https://test.salesforce.com/services/Soap/c/36.0/0DF8E00000000De

The ServerURL returned by the login method:
https://icl--Staging.cs87.my.salesforce.com/services/Soap/c/36.0/00D8E0000008itT/0DF8E00000000De

What I am doing wrong?
 
Best Answer chosen by Arcos
Daniel BallingerDaniel Ballinger
When you download the WSDL for your Apex defined web service it will include the endpoint URL that you should call. Try taking the host/domain part of the login ServerURL and combining it with the URL from the WSDL.

E.g.
 
<port binding="tns:TestClassBinding" name="TestClass">
<soap:address location="https://na5.salesforce.com/services/Soap/class/DFB/TestClass"/>
</port>

Note that my address in the WSDL here also has my /DFB/ namespace in the URL.

So you will most likely want something like:
 
https://icl--Staging.cs87.my.salesforce.com/services/Soap/class/ICL_GatewaySAP

See also: Exposing class as webservice (http://salesforce.stackexchange.com/q/70057/102)

All Answers

Daniel BallingerDaniel Ballinger
When you download the WSDL for your Apex defined web service it will include the endpoint URL that you should call. Try taking the host/domain part of the login ServerURL and combining it with the URL from the WSDL.

E.g.
 
<port binding="tns:TestClassBinding" name="TestClass">
<soap:address location="https://na5.salesforce.com/services/Soap/class/DFB/TestClass"/>
</port>

Note that my address in the WSDL here also has my /DFB/ namespace in the URL.

So you will most likely want something like:
 
https://icl--Staging.cs87.my.salesforce.com/services/Soap/class/ICL_GatewaySAP

See also: Exposing class as webservice (http://salesforce.stackexchange.com/q/70057/102)
This was selected as the best answer
ArcosArcos
Thanks, Daniel. I know this works, I was just wondering why Salesforce recommended approach doesn't work, what is the purpose of this ServerURL if it cannot be used. I would like to have a simple solution that doesn't require parsing and don't need to be changed anytime Salesforce decides to change how the address looks like. Do you think I should open a new case against Salesforce?
Daniel BallingerDaniel Ballinger
The integration between the various web services has always been a bit of a bodge job. For instance, the REST API doesn't have a native login resource outside of what the OAuth 2 flows provide. So often devs need to manually build the SOAP POST request to use the Partner API.

The instructions in Updating Hard-Coded References FAQ (https://help.salesforce.com/apex/HTViewSolution?urlname=Updating-Hard-Coded-References-FAQ&language=en_US) on how to update hard-coded references in integrations is correct if you are dealing is a single service. E.g. If you were only dealing with the Partner API, then it would be fine to use the returned serverUrl in to update the endpoint.

However, since you are taking the serverUrl from the Partner API and then using it with your custom Apex web service you will need to make some modifications. You could try a support case or sending feedback on the help article in question. I suspect you will get a similar answer.

You could try raising an idea to provide the web service urls in the Partner API LoginResult (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login_loginresult.htm). Note how the metadataServerUrl is already there. Of course, there could be a range of apex web services exposed in an org, so you would need to find them by a key of some sorts.

 
ArcosArcos
Thanks Daniel. I will use the endpoint specified in the WSDL for my WS.