1
我需要從Java中的UltiPro使用Web服務。所有來自UltiPro的例子都是針對C#的(見下文),我看不出如何將它轉換成Java。創建Java客戶端以訪問WSHTTPBINDING API服務
我的研究表明,關鍵是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;
}
}
你並不孤單。 Java - > .NET互操作性問題是最糟糕的。 – Matt1776
我放棄了這個嘗試。我們正在切換到.NET,所以它會變得更容易...... –