我是Web Services的新手。我正在创建Apache CXF(apache-cxf-2.5.0)基于SOAP的Web服务。它从Java类创建WSDL(Java第一种方法)。
以下是我的Java类:
package com.abcd.shoppingcart;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.jws.WebService;
import org.jboss.wsf.spi.annotation.WebContext;
import com.abcd.db.DBConnection;
@WebService(endpointInterface = "com.abcd.shoppingcart.GetMerchantsCardsListInterface", serviceName = "GetMerchantsCardsList4")
@WebContext( contextRoot = "/" , urlPattern="/SrvGetmerchantsCardsList.jsp" )
public class GetMerchantsCardsList4 implements GetMerchantsCardsListInterface {
private DBConnection dbConnection;
private Connection con = null;
private Statement stmt = null;
private ResultSet rset = null;
private String sqlSelect = null;
String[][] cardData = null;
int columnNo = 1, rowNo = 1, totalRows = 0, totalColumns = 6;
public String[][] returnMerchantsCardsList(int pageNumber, int recordsPerPage) {
dbConnection = new DBConnection();
sqlSelect = "SELECT "
+ " giftcard.MerchantId, giftcard.MerchantName, giftcard.ID AS GiftCardId, giftcardtransactions.CardNumber AS GiftCardNumber, "
+ " giftcardtransactions.CardValue, giftcardtransactions.ImageName "
+ " FROM merchant "
+ " INNER JOIN giftcard ON giftcard.MerchantId = merchant.ID "
+ " INNER JOIN giftcardtransactions ON giftcardtransactions.id = merchant.ID "
+ " WHERE merchant.isActive = '1' "
+ " GROUP BY giftcard.MerchantId";
try {
con = dbConnection.getConnection();
stmt = con.createStatement();
rset = stmt.executeQuery(sqlSelect);
rset.last();
totalRows = rset.getRow();
totalRows++;
totalColumns++;
cardData = new String[totalRows][totalColumns];
rset.beforeFirst();
while (rset.next()) {
columnNo = 1;
while (columnNo < totalColumns) {
cardData[rowNo][columnNo] = rset.getString(columnNo);
//System.out.print(cardData[rowNo][columnNo] + "\t\t");
columnNo++;
}
rowNo++;
System.out.println();
}
rset.close();
stmt.close();
con.close();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
}
return cardData;
}
}
这是在指定的URL处创建的WSDL:
<wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://shoppingcart.abcd.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="GetMerchantsCardsList4" targetNamespace="http://shoppingcart.abcd.com/">
<wsdl:types>
<xs:schema xmlns:ns1="http://jaxb.dev.java.net/array" xmlns:tns="http://shoppingcart.abcd.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://shoppingcart.abcd.com/">
<xs:import namespace="http://jaxb.dev.java.net/array"/>
<xs:element name="returnMerchantsCardsList" type="tns:returnMerchantsCardsList"/>
<xs:element name="returnMerchantsCardsListResponse" type="tns:returnMerchantsCardsListResponse"/>
<xs:complexType name="returnMerchantsCardsList">
<xs:sequence>
<xs:element name="pageNumber" type="xs:int"/>
<xs:element name="recordsPerPage" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="returnMerchantsCardsListResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="ns1:stringArray"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://jaxb.dev.java.net/array" version="1.0">
<xs:complexType final="#all" name="stringArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="returnMerchantsCardsList">
<wsdl:part element="tns:returnMerchantsCardsList" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="returnMerchantsCardsListResponse">
<wsdl:part element="tns:returnMerchantsCardsListResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="GetMerchantsCardsListInterface">
<wsdl:operation name="returnMerchantsCardsList">
<wsdl:input message="tns:returnMerchantsCardsList" name="returnMerchantsCardsList"></wsdl:input>
<wsdl:output message="tns:returnMerchantsCardsListResponse" name="returnMerchantsCardsListResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GetMerchantsCardsList4SoapBinding" type="tns:GetMerchantsCardsListInterface">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="returnMerchantsCardsList">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="returnMerchantsCardsList">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="returnMerchantsCardsListResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GetMerchantsCardsList4">
<wsdl:port binding="tns:GetMerchantsCardsList4SoapBinding" name="GetMerchantsCardsList4Port">
<soap:address location="http://localhost:8080/webservices/test/SrvGetmerchantsCardsList.jsp"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我正在使用soapUI进行测试。这是我使用soapUI时生成的请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shop="http://shoppingcart.abcd.com/">
<soapenv:Header/>
<soapenv:Body><shop:returnMerchantsCardsList>
<pageNumber>1</pageNumber>
<recordsPerPage>4</recordsPerPage>
</shop:returnMerchantsCardsList>
</soapenv:Body>
</soapenv:Envelope>
这是我第一次向指定端点URL提交请求时得到的响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:returnMerchantsCardsListResponse xmlns:ns2="http://shoppingcart.abcd.com/">
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item>3</item>
<item>Borders</item>
<item>224</item>
<item>jhgsjhdgjshgjjshsj</item>
<item>25.00</item>
<item>ord_mall.jpg</item>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item>5</item>
<item>Gap</item>
<item>210</item>
<item>jhgsjhdgjshgjjshsj</item>
<item>25.00</item>
<item>land_mall.jpg</item>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item>6</item>
<item>Fandango</item>
<item>211</item>
<item>asd78723642h36</item>
<item>25.00</item>
<item>game_mall.jpg</item>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item>8</item>
<item>AMC Theaters</item>
<item>212</item>
<item>jhgsjhdgjshgjjshsj</item>
<item>25.00</item>
<item>game_mall.jpg</item>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item>9</item>
<item>Macy{#}s</item>
<item>214</item>
<item>jhgsjhdgjshgjjshsj</item>
<item>25.00</item>
<item>mac_mall.jpg</item>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item>10</item>
<item>i-Tunes</item>
<item>215</item>
<item>jhgsjhdgjshgjjshsj</item>
<item>25.00</item>
<item>mac_mall.jpg</item>
</return>
</ns2:returnMerchantsCardsListResponse>
</soap:Body>
</soap:Envelope>
但是,当我再次重新提交请求时,每次提交请求时都会得到以下响应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:returnMerchantsCardsListResponse xmlns:ns2="http://shoppingcart.abcd.com/">
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
<return>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<item xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</return>
</ns2:returnMerchantsCardsListResponse>
</soap:Body>
</soap:Envelope>
实际上,当我第一次提交请求时,我期待相同的响应。但不知何故,每当我提交请求时,我都会在没有任何数据的情况下获得响应。如何摆脱这个?
谢谢。
答案 0 :(得分:1)
我的问题解决了。问题是变量,对象被声明的地方。之前我在类级别声明了那些变量,对象。我更改并声明了变量,方法中的对象,并且它有效。
谢谢。