2017-02-13 6 views
1

Java의 UltiPro에서 웹 서비스를 사용해야합니다. UltiPro의 모든 예제는 C# 용이며 (아래 참조) Java로 변환하는 방법을 볼 수 없습니다.WSHTTPBINDING API 서비스에 액세스하기위한 Java 클라이언트 생성

내 연구 결과에 따르면 키가 WSHttpBinding 인 것으로 나타났습니다. UltiPro의 문서는 그들이 말하는 것을 XML 파일을 포함

...

다음 코드는 UltiPro 데이터에 대한 인증의 XML 예제입니다. 요청의 전체 내용을 복사하고 값을 업데이트 할 수 있습니다. 응답 예는 성공적인 응답의 형식을 지정합니다.

이전에 많은 웹 서비스 및 RESTful 프로그램을 작성했지만이 문제에 집착하고 있습니다.

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
    <s:Header> 
<a:Action s:mustUnderstand="1">http://www.ultipro.com/services/loginservice/ILoginService/Authenticate</a:Action> 
     <h:ClientAccessKey xmlns:h="http://www.ultipro.com/services/loginservice">CAK</h:ClientAccessKey> 
     <h:Password xmlns:h="http://www.ultipro.com/services/loginservice">PASSWORD</h:Password> 
     <h:UserAccessKey xmlns:h="http://www.ultipro.com/services/loginservice">USER API KEY</h:UserAccessKey> 
     <h:UserName xmlns:h="http://www.ultipro.com/services/loginservice">USERNAME</h:UserName> 
     </s:Header> 
    <s:Body> 
     <TokenRequest xmlns="http://www.ultipro.com/contracts" /> 
    </s:Body> 
</s:Envelope> 

C# 코드 :

namespace ConsoleSample 
{ 
    using System; 
    using System.ServiceModel; 
    using System.ServiceModel.Channels; 

    using ConsoleSample.LoginService; 

    public class Program 
    { 
     internal static void Main(string[] args) 
     { 
      // Setup your user credentials: 
      const string UserName = ""; 
      const string Password = ""; 
      const string UserApiKey = ""; 
      const string CustomerApiKey = ""; 

      // Create a proxy to the login service: 
      var loginClient = new LoginServiceClient("WSHttpBinding_ILoginService"); 

      try 
      { 
       // Submit the login request to authenticate the user: 
       string message; 
       string authenticationToken; 

       AuthenticationStatus loginRequest = 
        loginClient 
         .Authenticate(
          CustomerApiKey, 
          Password, 
          UserApiKey, 
          UserName, 
          out message, 
          out authenticationToken); 

       if (loginRequest == AuthenticationStatus.Ok) 
       { 
        // User is authenticated and the authentication token is provided. 
        Console.WriteLine("User authentication successful."); 
       } 
       else 
       { 
        // User authentication has failed. Review the message for details. 
        Console.WriteLine("User authentication failed: " + message); 
       } 

       loginClient.Close(); 

       Console.WriteLine("Press a key to exit..."); 
       Console.ReadKey(true); 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine("Exception: " + ex); 
       loginClient.Abort(); 
       throw; 
      } 
     } 
+0

당신은 혼자가 아닙니다 :

나는 성공적으로 다음 코드를 사용하여 인증 할 수 있었다. Java ->. NET interop 문제는 최악입니다. – Matt1776

+1

나는 이것을 시험에서 포기했다. 우리는 .NET으로 전환하여 어쨌든 더 쉬워 질 것입니다. –

답변

0

나는 당신이 자바에 쓰기 찾고 있습니다하지만 어쩌면 내 코드에서 뭔가 도움이 될 것 이해합니다.

<?php 
$url    = 'https://rental5.ultipro.com/services/LoginService'; 
$action   = 'http://www.ultipro.com/services/loginservice/ILoginService/Authenticate'; 
$username  = 'MY_USERNAME'; 
$password  = 'MY_PASSWORD'; 
$userAccessKey = 'MY_USER_ACCESS_KEY'; 
$clientAccessKey = 'MY_CLIENT_ACCESS_KEY'; 

$loginPayload =<<<EOD 
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">{$action}</a:Action> 
     <h:ClientAccessKey xmlns:h="http://www.ultipro.com/services/loginservice">{$clientAccessKey}</h:ClientAccessKey> 
     <h:Password xmlns:h="http://www.ultipro.com/services/loginservice">{$password}</h:Password> 
     <h:UserAccessKey xmlns:h="http://www.ultipro.com/services/loginservice">{$userAccessKey}</h:UserAccessKey> 
     <h:UserName xmlns:h="http://www.ultipro.com/services/loginservice">{$username}</h:UserName> 
    </s:Header> 
    <s:Body> 
     <TokenRequest xmlns="http://www.ultipro.com/contracts" /> 
    </s:Body> 
</s:Envelope> 
EOD; 

$client = new SoapClient(
    null, 
    array(
     'location'  => $url, 
     'uri'   => '', 
     'trace'  => 1, 
     'encoding'  => 'UTF-8', 
     'use'   => SOAP_LITERAL, 
     'soap_version' => SOAP_1_2 
    ) 
); 

try { 
    $order_return = $client->__doRequest($loginPayload, $url, $action, SOAP_1_2, 0); 

    $getLastRequestHeaders = $client->__getLastRequestHeaders(); 
    $getLastRequest = $client->__getLastRequest(); 
    $getLastResponseHeaders = $client->__getLastResponseHeaders(); 
    $getLastResponse = $client->__getLastResponse(); 

    echo "<pre>"; 
    echo $getLastRequestHeaders; 
    echo '<br>'; 
    echo $getLastResponseHeaders; 
    echo '<br>'; 
    print_r($order_return); 
    echo "</pre>"; 

} catch (SoapFault $exception) { 
    var_dump(get_class($exception)); 
    var_dump($exception); 
} 
?>