2017-02-13 25 views
1

JavaのUltiProからWebサービスを使用する必要があります。 UltiProのすべての例はC#用です(下記参照)、Javaへの変換方法はわかりません。WSHTTPBINDING APIサービスにアクセスするためのJavaクライアントの作成

私の研究は、キーがWSHttpBindingであることを示しています。

UltiProのドキュメントは、彼らが言うXMLファイルが含まれています...

次のコードでは、あなたのUltiProデータへの認証のXMLの例です。リクエスト全体の内容をコピーし、値を更新することができます。応答の例は、正常な応答のフォーマット方法を示しています。

これまでに多くのWebサービスと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

私はあなたがJAVAでそれを書くために探しているが、おそらく私のコードから何かが役立ちます理解しています。

<?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); 
} 
?> 
関連する問題