gpt4 book ai didi

c# - 理解 wsdl 服务的 java 类

转载 作者:行者123 更新时间:2023-12-01 15:34:59 26 4
gpt4 key购买 nike

我正在尝试用java编写wsdl Web服务的测试代码。该代码返回一些变量值并且必须下订单。这段代码我在 C# 上有等效的代码,但我不明白如何在 java 中转换。这是我的 Java 代码:

 package betdaqclient; 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.xml.bind.JAXBElement;
public class test
{
public static void main(String[] args)
{
ExternalApiHeader externalAPIHeader = new ExternalApiHeader();
externalAPIHeader.languageCode = "en";
externalAPIHeader.username = "myusername";
externalAPIHeader.password = "mypassword";
externalAPIHeader.version = new BigDecimal ("2.0");

ReadOnlyService_Service ro = new ReadOnlyService_Service();
ReadOnlyService readOnlyService = ro.getReadOnlyService();
SecureService_Service ss = new SecureService_Service();
SecureService secureService = ss.getSecureService();


GetAccountBalancesRequest getAccountBalanceRequest = new GetAccountBalancesRequest();
GetAccountBalancesResponse2 getAccountBalanceResponse = secureService.getAccountBalances(getAccountBalanceRequest, externalAPIHeader);
System.out.printf("%n%nUser : " + externalAPIHeader.username);
System.out.printf("%nBalance : " + getAccountBalanceResponse.balance.toString());
System.out.printf("%nExposure : " + getAccountBalanceResponse.exposure.toString());
System.out.printf("%nAvailable: " + getAccountBalanceResponse.availableFunds.toString()+"%n");



SimpleOrderRequest bet = new SimpleOrderRequest();

bet.selectionId = (long) IdMarket;

bet.polarity = (byte) 1 ; //<-----BACK?

bet.stake = new BigDecimal("1.00") ;

bet.price = new BigDecimal("1.01") ;
bet.cancelOnInRunning = true ;





PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();

/* Lacking Code */





PlaceOrdersNoReceiptResponse2 response = secureService.placeOrdersNoReceipt(request,externalAPIHeader);


}
}

我猜我的bet必须在列表中转换,然后传递给request。这是我在示例中找到的 C# 代码:

    public long[] PlaceOrdersNoReceipt(long selectionId, byte polarity, decimal amount

, decimal odds, byte resetCount)

{

SimpleOrderRequest order = new SimpleOrderRequest();

order.SelectionId = selectionId;

order.Polarity = polarity;

order.Stake = amount;

order.Price = odds;

order.ExpectedSelectionResetCount = resetCount;





PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();

request.Orders = new SimpleOrderRequest[1] {order};





PlaceOrdersNoReceiptResponse response = _proxy.PlaceOrdersNoReceipt(request);

if (response.ReturnStatus.Code != 0)

throw new Exception(response.ReturnStatus.Description);





return response.OrderHandles;

}

这是从 wsdl 构建的类的定义:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PlaceOrdersNoReceiptRequest", propOrder = {
"orders",
"wantAllOrNothingBehaviour"
})
public class PlaceOrdersNoReceiptRequest {

@XmlElement(name = "Orders", required = true)
protected PlaceOrdersNoReceiptRequest.Orders orders;
@XmlElement(name = "WantAllOrNothingBehaviour")
protected boolean wantAllOrNothingBehaviour;

public PlaceOrdersNoReceiptRequest.Orders getOrders() {return orders;}


public void setOrders(PlaceOrdersNoReceiptRequest.Orders value) {this.orders = value;}


public boolean isWantAllOrNothingBehaviour() { return wantAllOrNothingBehaviour; }
public void setWantAllOrNothingBehaviour(boolean value) {this.wantAllOrNothingBehaviour = value;}


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"order"})
public static class Orders {

@XmlElement(name = "Order", required = true)
protected List<SimpleOrderRequest> order;
public List<SimpleOrderRequest> getOrder() {
if (order == null) {
order = new ArrayList<SimpleOrderRequest>();
}
return this.order;
}

}

}

问题是我如何将 SimpleOrderRequest 类的 bet 元素转换为 PlaceOrderNoRecepeit 类的 request > ?可能是一个非常愚蠢的问题,但我是java编程的新手。

最佳答案

缺少的代码应该是

PlaceOrdersNoReceiptRequest.Orders orders = new PlaceOrdersNoReceiptRequest.Orders();
orders.getOrder().add(bet);

PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();
request.setOrders(orders);

关于c# - 理解 wsdl 服务的 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9008903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com