在我自学 SOAP 的过程中,我试图提出一个请求:
1. 为了进行测试,我使用了交易者的 api wsdl .
2.借助maven-jaxb2-plugin
生成java类。
3. 其中包括:ObjectFactory、TokenRequest、TokenResponse、GetInfoRequest
。
4. 我正在通过 ObjectFactory
创建新对象,并且我认为我正在执行一个请求:
ObjectFactory factory = new ObjectFactory();
TokenRequest tokenRequest = factory.createTokenRequest();
tokenRequest.setLogin(12345);
tokenRequest.setPassword(factory.createTokenRequestPassword("password"));
TokenResponse tokenResponse = factory.createTokenResponse();
GetInfoRequest getInfoRequest = factory.createGetInfoRequest();
getInfoRequest.getLogin(); //It's null
为什么我在那里得到空(我错过了什么)?我什至提出要求吗?如何追踪我是否真的成功了?
最佳答案
Do I even make a request?
不,您没有执行请求,您只是在那里创建对象
检查生成的类中是否有两个名为 ClientTradingService
和 IClientTradingApi
的类,您必须使用它们来执行请求。
ObjectFactory factory = new ObjectFactory();
TokenRequest tokenRequest = factory.createTokenRequest();
tokenRequest.setLogin(12345);
tokenRequest.setPassword(factory.createTokenRequestPassword("password"));
//create your service should be something similar to this
ClientTradingService service = new ClientTradingService();
IClientTradingApi iservice = service.getBasicHttpBindingIClientTradingApi();
//do your request should be something similar to this
TokenResponse tokenResponse = iservice.getAuthenticationToken(tokenRequest);
//now you can get the info from the response
tokenResponse.getToken();//this should return the authentication token
要做其他一些请求,过程与上面的完全一样。
关于Java SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44314631/