如何通过独立的SOAP客户端调用SalesForce SOAP方法

时间:2015-04-03 16:34:09

标签: web-services soap salesforce soapui soap-client

我可以使用步骤here调用SalesForce。但是,当我尝试使用独立的Web客户端like this one进行呼叫时,我收到错误。错误如下。提供给login()的用户名和(密码+令牌)有效。

我不确定为什么我无法从独立的SOAP客户端调用SOAP方法。我相信我应该能够。我是否必须始终使用Force-wsc连接到SalesForce?

请求:

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <login xmlns="urn:enterprise.soap.sforce.com">
      <username>MY_USERNAME</username>
      <password>PASSWORD+TOKEN</password>
    </login>
  </soap:Body>
</soap:Envelope>

响应

ResponseCode: 500 (Server Error)
Transfer-Encoding:chunked
Content-Type:text/xml;charset=UTF-8
Date:Fri, 03 Apr 2015 16:25:47 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie:BrowserId=KUXkegaIQ_aJnfVrQEeC-A;Path=/;Domain=.salesforce.com;Expires=Tue, 02-Jun-2015 16:25:47 GMT

<?xml version="1.0" encoding="utf-16"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>INVALID_LOGIN</faultcode>
      <faultstring>INVALID_LOGIN: Invalid username, password, security token; or user locked out.</faultstring>
      <detail>
        <sf:LoginFault xsi:type="sf:LoginFault">
          <sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode>
          <sf:exceptionMessage>Invalid username, password, security token; or user locked out.</sf:exceptionMessage>
        </sf:LoginFault>
      </detail>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

控制台出错:

    ************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Web.Services.Protocols.SoapException: INVALID_LOGIN: Invalid username, password, security token; or user locked out.
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at SforceService.login(String username, String password)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at WebServiceStudio.MainForm.InvokeWebMethod()

客户端屏幕截图:

enter image description here

3 个答案:

答案 0 :(得分:0)

连接器使用会话标头而不是用户名和密码,因此您可以生成SF会话并在独立客户端设置中输入标头。 请看这里的第105行https://github.com/forcedotcom/wsc/blob/master/src/main/java/com/sforce/ws/transport/SoapConnection.java

                SessionRenewer.SessionRenewalHeader sessionHeader = config.getSessionRenewer().renewSession(config);
                if (sessionHeader != null) {
                    addHeader(sessionHeader.name, sessionHeader.headerElement);
                }

答案 1 :(得分:0)

我能想到的唯一一件事就是你可能正在向错误的网址发送电话?它是测试或生产组织吗?

答案 2 :(得分:0)

您的xml请求没问题。只需检查端点(如果您正在使用生产wsdl,使用生产凭据,相同的沙箱 - 或只是更改服务的端点 - )。如果您支持代理,我建议您查看.Net webservice studio设置以在那里设置代理设置。

希望这有帮助