2011-02-26 52 views
0

我试图生成客户端代码与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); 
+1

您可能有更好的运气在此stackoverflow.com – Olli 2011-02-26 17:27:52

回答

1

当使用现有的WSDL,我总是用SoapUI快速原型和看到的方法服务提供 - 有该软件的免费社区版。并且,它也有一个Eclipse plugin它与独立版本相同。

+0

谢谢! SoapUI是我正在努力完成的伟大工具。 – spinlock 2011-02-28 23:52:19

+0

很高兴喜欢它。 – 2011-03-01 09:42:02