2
我試圖寫一個Java客戶端這個Web服務使用SOAP在Java中與API認證使用Web服務
http://api.exigo.com/3.0/ExigoApi.asmx?WSDL
,但不能設置它的認證頭 在.NET環境中有一個屬性該組的ApiAuthentication對象API 對象這樣
//Set Authentication Header
ExigoApi api = new ExigoApi();
ApiAuthentication auth = new ApiAuthentication();
auth.Company = "company";
auth.LoginName = "name";
auth.Password = "password";
api.ApiAuthenticationValue = auth;
//Create request object
GetCustomersRequest req = new GetCustomersRequest();
//Specify which customer(s) we are getting
req.CustomerID = 1;
//Submit the request
GetCustomersResponse res = api.GetCustomers(req);
Console.WriteLine(res.Customers[0].CustomerID);
但在Java中我無法找到這種方法
api.ApiAuthenticationValue = auth;
這是我用Java編寫的代碼,但拋出異常
import com.exigo.api.*;
public class ExigoDemoService {
public static void main(String[] args) {
//Set Authentication Header
ExigoApi api = new ExigoApi();
ApiAuthentication auth = new ApiAuthentication();
auth.setCompany("company");
auth.setLoginName("name");
auth.setPassword("password");
//Create request object
GetCustomersRequest req = new GetCustomersRequest();
//Specify which customer(s) we are getting
req.setCustomerID(1);
//Submit the request
GetCustomersResponse res = api.getExigoApiSoap().getCustomers(req);
}
private static CreateCustomerResponse createCustomer(com.exigo.api.CreateCustomerRequest createCustomerRequest) {
com.exigo.api.ExigoApi service = new com.exigo.api.ExigoApi();
com.exigo.api.ExigoApiSoap port = service.getExigoApiSoap();
return port.createCustomer(createCustomerRequest);
}
private static GetCustomersResponse getCustomers(com.exigo.api.GetCustomersRequest getCustomersRequest) {
com.exigo.api.ExigoApi service = new com.exigo.api.ExigoApi();
com.exigo.api.ExigoApiSoap port = service.getExigoApiSoap();
return port.getCustomers(getCustomersRequest);
}
}
拋出異常是
Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Authentication header missing!
Unable to Authenticate!
會有人幫我?請讓我真的被困在這裏 –