0

i am trying to write a test code of wsdl web service in java. This code return me some values of variables and have to place an order. Of this code i have en equivalent on C# but i don't understand how to convert in java. This is my code in 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);


}
} 

I guess that my bet has to be converted in a list and then passed to request. This is the code in C# that i have found in the examples:

    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;

    }

This is the definition of the class built from 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;
    }

}

}

The question is how i have to convert bet element of thee class SimpleOrderRequest into request of the class PlaceOrderNoRecepeit ? May be a very stupid question but i am a newbie in java programming.

emanuele
  • 2,519
  • 8
  • 38
  • 56
  • Have you tried [http://stackoverflow.com/questions/858572/how-to-make-a-new-list-in-java](http://stackoverflow.com/questions/858572/how-to-make-a-new-list-in-java)... request.Orders = Arrays.asList(new SimpleOrderRequest[] { bet } )? – Raj Ranjhan Jan 25 '12 at 20:13

1 Answers1

1

Lacked code should be

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

PlaceOrdersNoReceiptRequest request = new PlaceOrdersNoReceiptRequest();
request.setOrders(orders);
e-zinc
  • 4,491
  • 2
  • 20
  • 17