2012-06-26 3 views
4

Apex-Webservice에 대한 연결을 설정하려고 시도 중이지만 매번 실패합니다. here을 설명 나는 다만 방법,Salesforce Apex Soap 웹 서비스 (Java)

global class AtlassianService 
{ 
    webService static String hello(String Name) 
    { 
     return 'Hello '+Name+' ! :D'; 
    } 
} 

는 클라이언트를 생성하려면 :

java –classpath pathToJAR/wsc-22.jar com.sforce.ws.tools.wsdlc pathToWsdl/WsdlFilename​ pathToOutputJar/OutputJarFilename 

WebService에 액세스 : 나는 PartnerConnection를 사용하는 경우

SoapConnection soap = Connector.newConnection("[email protected]", "XXXX"); 

System.out.println(soap.hello("WORLD")); // Invalid Session (=> SessionID is null) 

내 Webserce은 매우 간단합니다 유효한 SessionID를 얻으려면 모두 잘 작동합니다.

ConnectorConfig config = new ConnectorConfig(); 
config.setUsername(username); 
config.setPassword(password); 
config.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/24.0"); 

new PartnerConnection(config); 

SoapConnection soap = Connector.newConnection(null, null); 
soap.setSessionHeader(config.getSessionId()); 

System.out.println(soap.hello("WORLD")); 

누구나 첫 번째 예제가 실패하는 이유는 무엇입니까?

인사말 세바스찬

답변

0

WSC의 모든 작업 호출이 ConnectionException를 발생하거나 중 하나가 오류의 경우에는 구체적인 하위 유형입니다. 따라서 문제를 해결하는 데 도움이되는 오류 메시지를 받아야합니다. 당신의 ConnectorConfig의 초기화 한 후 다음 줄을 추가 WSC에 의해 전송 및 수신 SOAP 메시지를 디버깅하기 위해이 전체 XML을 꽤 - 인쇄 할

conf.setPrettyPrintXml(true); 
conf.setTraceMessage(true); 

클라이언트와 웹 서비스 사이에 교환. resoponse는 아마도 문제의 원인을 찾는 데 도움이 될 것입니다.

희망이 도움이됩니다. h9nry

8

AtlassianService wsdl에는 Salesforce에서 인증 할 로그인 메소드가 포함되어 있지 않으므로 WSC에서 생성 한 프록시 클래스에는 실제로 로그인을 수행 할 수있는 코드가 없기 때문에 발생한다고 가정합니다.

나는 귀하의 질문과 매우 유사하게 (Enterprise API 사용) 시도하고있었습니다. 내가 찾은 해결책은이었다

  1. 이 Enterprise.wsdl (enterprise.jar)에 대한 WSC를 사용하여 프록시 클래스
  2. MyWebservice.wsdl (mywebservice.jar)에 대한 WSC를 사용하여 프록시 클래스를 생성
  3. 가와의 연결을 만들기 생성 Enterprise 및 SessionId 가져 오기
  4. 요청의 SessionId를 MyWebservice로 설정하십시오.
  5. MyWebservice 메서드 호출을 수행하십시오. 이처럼

:

import com.sforce.soap.MyWebservice.SoapConnection; 
import com.sforce.soap.MyWebservice.Connector; 

import com.sforce.ws.ConnectionException; 
import com.sforce.ws.ConnectorConfig; 
import com.sforce.soap.enterprise.*; 


public class CallWS { 


    static final String USERNAME = "username"; 
    static final String PASSWORD = "pass+securitytoken"; 

    static SoapConnection MyWebserviceWSconnection; 
    static EnterpriseConnection enterpriseConnection; 

    public static void main(String[] args) { 

    ConnectorConfig config = new ConnectorConfig(); 
    config.setUsername(USERNAME); 
    config.setPassword(PASSWORD); 


    try { 

     //create a connection to Enterprise API -- authentication occurs 
     enterpriseConnection = com.sforce.soap.enterprise.Connector.newConnection(config);  
     // display some current settings 
     System.out.println("Auth EndPoint: "+config.getAuthEndpoint()); 
     System.out.println("Service EndPoint: "+config.getServiceEndpoint()); 
     System.out.println("Username: "+config.getUsername()); 
     System.out.println("SessionId: "+config.getSessionId()); 


     //create new connection to exportData webservice -- no authentication information is included 
     MyWebserviceWSconnection = Connector.newConnection("",""); 
     //include session Id (obtained from enterprise api) in exportData webservice 
     MyWebserviceWSconnection.setSessionHeader(config.getSessionId()); 


     String result = MyWebserviceWSconnection.receiveData("test"); 
     System.out.println("Result: "+result); 


    } catch (ConnectionException e1) { 
     e1.printStackTrace(); 
    } 
    } 
}