企業常同時擁有 J2EE 與 .NET 平台的細粒度業務服務。BPEL 作為 SOA 編排標準,基於 WSDL/XML Schema 定義流程,但異構平台間的互操作性問題(XML 命名空間、復雜類型數組、日期時間類型)往往導致集成失敗。關鍵在於先設計 XSD Schema,再生成代碼(契約優先),而非反向生成 WSDL。
https://schema.a.supplier(域名反寫避免包名衝突)Product complexType:_name(string)、_price(float)、_qty(int)、_refurbished(boolean)getQuoteRequest/getQuoteResponse 消息getQuote 操作document/literal,Service 端點地址// Product 類添加構造器
public Product(String name, int qty, float price, boolean refurbished) { ... }
// SupplierAQuoteServiceBindingImpl
private static Hashtable inventory = new Hashtable();
public SupplierAQuoteServiceBindingImpl() {
inventory.put("IBM ThinkPad T40", new Product("IBM ThinkPad T40", 200, 1499.99f, false));
inventory.put("Dell Inspiron 4000", new Product("Dell Inspiron 4000", 100, 999.99f, true));
}
public Product getQuote(String productName) {
return inventory.containsKey(productName) ? (Product)inventory.get(productName)
: new Product(productName, 0, 0f, false);
}
https://schema.b.supplierDateInfo:_date(dateTime)、_desc(string)ArrayOfDateInfo:minOccurs=0, maxOccurs=unbounded 的 DateInfo 元素序列Product:_name、_qty、_price、_dates(ArrayOfDateInfo)productItem (type=Product) 供 xsd.exe 生成類// 運行: xsd.exe SupplierBSchema.xsd /classes → SupplierBSchema.cs
// 修改 SupplierBQuoteService.asmx
[WebService(Namespace="https://b.supplier/service")]
public class SupplierBQuoteService {
private static Hashtable inventory;
public SupplierBQuoteService() {
inventory = new Hashtable();
inventory.Add("IBM ThinkPad T40", new Product("IBM ThinkPad T40", 200, 1399.99f,
new DateInfo[]{ new DateInfo(DateTime.Now, "Manufacture Date"),
new DateInfo(DateTime.Now.AddYears(3), "Expiry Date") }));
// ... 其他產品
}
[WebMethod]
public Product getQuote(string quoteItemName) {
return inventory.ContainsKey(quoteItemName) ? (Product)inventory[quoteItemName]
: new Product(quoteItemName, 0, 0, new DateInfo[]{...});
}
}
瀏覽器測試 https://localhost/SupplierB/SupplierBQuoteService.asmx?wsdl 確認 WSDL 正確。
ProductQuotes:SupplierAQuote(SupplierASchema:Product)、SupplierBQuote(SupplierBSchema:Product)getQuotesRequest(productName)、getQuotesResponse(quotes:ProductQuotes)QuotesProcess (Sequence-based BPEL)// 從流程 WSDL 生成 JAX-RPC Proxy
QuotesProcessPortTypeProxy proxy = new QuotesProcessPortTypeProxy();
ProductQuotes result = proxy.getQuotes("IBM ThinkPad T40");
Product quoteA = result.getSupplierAQuote();
Product quoteB = result.getSupplierBQuote();
System.out.println("Supplier A: Qty=" + quoteA.get_qty() + ", Price=" + quoteA.get_price()
+ ", Refurbished=" + quoteA.is_refurbished());
System.out.println("Supplier B: Qty=" + quoteB.get_qty() + ", Price=" + quoteB.get_price());
DateInfo[] dates = quoteB.get_dates().get_dateInfo();
for (DateInfo d : dates) {
Calendar cal = d.get_date(); Date dt = cal.getTime();
System.out.println(d.get_desc() + ": " + dt);
}
https://schema.a.supplier)避免衝突ArrayOfXxx 包裝器類型,minOccurs=0, maxOccurs=unboundedxsd:dateTime,Java 映射 Calendar,客戶端轉 Date 顯示