Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java中的SOAP和API身份验证使用Web服务_Java_Web Services_Soap_Wsdl - Fatal编程技术网

使用java中的SOAP和API身份验证使用Web服务

使用java中的SOAP和API身份验证使用Web服务,java,web-services,soap,wsdl,Java,Web Services,Soap,Wsdl,我正在尝试为此web服务编写一个java客户机 但无法设置其身份验证标头 在.Net环境中,有一个属性将的API身份验证对象设置为API 像这样的物体 //Set Authentication Header ExigoApi api = new ExigoApi(); ApiAuthentication auth = new ApiAuthentication(); auth.Company = "company"; auth.LoginName = "

我正在尝试为此web服务编写一个java客户机

但无法设置其身份验证标头 在.Net环境中,有一个属性将的API身份验证对象设置为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!
所以我解决了这个问题:

ExigoApiLocator service = null;
ExigoApiSoap port = null;

service = new ExigoApiLocator();
port = service.getExigoApiSoap();


ApiAuthentication authentication = new ApiAuthentication();
authentication.setCompany("XYZCompany");
authentication.setLoginName("XYZAPIUser");
authentication.setPassword("XYZPassword");
authentication.setRequestTimeUtc(Calendar.getInstance());

((Stub) port).setHeader("http://api.exigo.com/", "ApiAuthentication", authentication);

有人能帮我吗?拜托,我真的被困在这里了