我试图生成客户端代码与Web服务进行交互,但我很难找出哪些过程调用我可以对服务器。我认为在Eclipse中构建这将是一个很好的捷径,可以帮助我理解API,但我不知道从哪里开始使用Eclipse。现在,我使用Axis2和运行WSDL2Java的命令行:如何配置Eclipse以使用Web服务?
wsdl2java.sh -uri http://www.xignite.com/xQuotes.asmx?WSDL -s -ap -o xignite
这生成所有我需要的存根,但我需要我的凭据添加到页眉和示例代码(如下)给出了适当的功能作为Header1(),但这是不正确的,我需要找到正确的功能。
//Instantiate the service
XigniteQuotesXigniteQuotesSoapStub stub = new XigniteQuotesXigniteQuotesSoapStub();
//Instantiate the objects that will let you build the SOAP Header
Header1 header = new Header1();
//Create the Header
Header h = new Header();
//Assign your email address ([email protected]) to the Username element
h.setUsername("[email protected]");
//Set the password
h.setPassword("");
//Set the SOAP header
header.setHeader(h);
//Create the arguments needed for the call
GetQuotes getQuotes = new GetQuotes();
getQuotes.setSymbol("msft,aapl");
//Make the call with the arguments and the header
GetQuotesResponse response = stub.GetQuotes(getQuotes, header);
您可能有更好的运气在此stackoverflow.com – Olli 2011-02-26 17:27:52