使用AXIS1.4访问web Service问题

awa2008 2011-09-22 05:30:59
对方的webservice提供了wsdl文件,还提供了licenseXml,文档中说是SOAP消息的传入格式:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthenticationToken xmlns="bookService">
<Username>…</Username>
<Password>…</Password>
<licenseXml>…</licenseXml>
</AuthenticationToken>
</soap:Header>
<soap:Body>

</soap:Body>
</soap:Envelope>



我自己做了一个WebService来做测试(写了一个ws 服务端,同wsdl2java.bat的方法做了一个ws 客户端)

我通过wsdl2java.bat文件生成相关代码,命令格式为:
wsdl2java -uri http://localhost:8080/test/services/BookService?wsdl -p demo.test -d adb -s -o d:\data

测试代码服务端实现类的代码如下:

package org.codehaus.xfire.demo;

import java.util.HashMap;
import java.util.Map;

/**
* @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
* @author <a href="mailto:nathanyp@hotmail.com">Nathan Peles</a>
*/
//START SNIPPET: book
public class BookServiceImpl implements BookService
{
private Book onlyBook;
private Book twoBook;

public BookServiceImpl()
{
onlyBook = new Book();
onlyBook.setAuthor("Dan Diephouse");
onlyBook.setTitle("Using XFire");
onlyBook.setIsbn("0123456789");

twoBook = new Book();
twoBook.setAuthor("zhangweihua");
twoBook.setTitle("Study Web Service");
twoBook.setIsbn("2222222");
}

public Book[] getBooks()
{
return new Book[] { onlyBook, twoBook };
}

public Book findBook(String isbn) throws BookException
{
if (isbn.equals(onlyBook.getIsbn())){
return onlyBook;
}else if(isbn.equals(twoBook.getIsbn())){
return twoBook;
}
throw new BookException("Book not exists",new BookExceptionDetail("NOT_EXIST","Can't find book"));
}

public Map getBooksMap() {
Map result = new HashMap();
result.put(onlyBook.getIsbn(), onlyBook);
return result;
}
}

测试代码客户端代码如下:
package demo.test;

public class BookServiceClient {
public static void main(java.lang.String args[]){
try{
BookServiceStub stub =
new BookServiceStub
("http://localhost:8087/xfire/services/BookService");

getBooks(stub);
findBook(stub);

} catch(Exception e){
e.printStackTrace();
}
}


/* two way call/receive */
public static void getBooks(BookServiceStub stub){
try{
BookServiceStub.GetBooks req = new BookServiceStub.GetBooks();
BookServiceStub.GetBooksResponse res = stub.getBooks(req);
System.out.println(res.getOut());
BookServiceStub.ArrayOfBook bookArray = res.getOut();
for(int i = 0; i < bookArray.localBook.length; i++){
BookServiceStub.Book book = bookArray.localBook[i];
System.out.println("i=" + i + " Title=" + book.getTitle());
}
} catch(Exception e){
e.printStackTrace();
System.err.println("\n\n\n");
}
}


public static void findBook(BookServiceStub stub){
try{
BookServiceStub.FindBook req = new BookServiceStub.FindBook();

req.setIn0("2222222");
BookServiceStub.FindBookResponse res = stub.findBook(req);
System.out.println(res.getOut());
//BookServiceStub.ArrayOfBook bookArray = res.getOut();
BookServiceStub.Book book = res.getOut();
if(book != null){
System.out.println("have found book:" + book.getTitle());
}
} catch(Exception e){
e.printStackTrace();
System.err.println("\n\n\n");
}
}

}

这个测试能够通过,但是用户给到的要用licenseXml,不知道用这种方法如何使用licenseXml?请高手们指点一下!谢谢!
...全文
150 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
awa2008 2011-09-22
  • 打赏
  • 举报
回复
不是吧,怎么没人回帖啊?
awa2008 2011-09-22
  • 打赏
  • 举报
回复
测试类的WSDL内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://xfire.codehaus.org/BookService" xmlns:tns="http://xfire.codehaus.org/BookService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://demo.xfire.codehaus.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xfire.codehaus.org/BookService">
<xsd:element name="getBooksMap">
<xsd:complexType/>
</xsd:element>
<xsd:complexType name="anyType2anyTypeMap">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="entry">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="key" type="xsd:anyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="value" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="getBooksMapResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="tns:anyType2anyTypeMap"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getBooks">
<xsd:complexType/>
</xsd:element>
<xsd:element name="getBooksResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="ns1:ArrayOfBook"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="findBook">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="findBookResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="ns1:Book"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="BookExceptionDetail" type="ns1:BookExceptionDetail"/>
</xsd:schema>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://demo.xfire.codehaus.org">
<xsd:complexType name="ArrayOfBook">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Book" nillable="true" type="ns1:Book"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Book">
<xsd:sequence>
<xsd:element minOccurs="0" name="author" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="isbn" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="title" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BookExceptionDetail">
<xsd:sequence>
<xsd:element minOccurs="0" name="code" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="detailMessage" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getBooksRequest">
<wsdl:part name="parameters" element="tns:getBooks">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getBooksMapRequest">
<wsdl:part name="parameters" element="tns:getBooksMap">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getBooksMapResponse">
<wsdl:part name="parameters" element="tns:getBooksMapResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="BookExceptionDetail">
<wsdl:part name="BookExceptionDetail" element="tns:BookExceptionDetail">
</wsdl:part>
</wsdl:message>
<wsdl:message name="findBookRequest">
<wsdl:part name="parameters" element="tns:findBook">
</wsdl:part>
</wsdl:message>
<wsdl:message name="findBookResponse">
<wsdl:part name="parameters" element="tns:findBookResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getBooksResponse">
<wsdl:part name="parameters" element="tns:getBooksResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="BookServicePortType">
<wsdl:operation name="getBooksMap">
<wsdl:input name="getBooksMapRequest" message="tns:getBooksMapRequest">
</wsdl:input>
<wsdl:output name="getBooksMapResponse" message="tns:getBooksMapResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getBooks">
<wsdl:input name="getBooksRequest" message="tns:getBooksRequest">
</wsdl:input>
<wsdl:output name="getBooksResponse" message="tns:getBooksResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findBook">
<wsdl:input name="findBookRequest" message="tns:findBookRequest">
</wsdl:input>
<wsdl:output name="findBookResponse" message="tns:findBookResponse">
</wsdl:output>
<wsdl:fault name="BookExceptionDetail" message="tns:BookExceptionDetail">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BookServiceHttpBinding" type="tns:BookServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getBooksMap">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBooksMapRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getBooksMapResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getBooks">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getBooksRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getBooksResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findBook">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="findBookRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="findBookResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="BookExceptionDetail">
<wsdlsoap:fault name="BookExceptionDetail" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BookService">
<wsdl:port name="BookServiceHttpPort" binding="tns:BookServiceHttpBinding">
<wsdlsoap:address location="http://localhost:8087/xfire/services/BookService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧