Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Loading a ListGrid From WSDL Web Service HowTo

    SmartGWT Power, 12/19/2010 Nightly Build

    I've been reading the docs and the forum as well as the 2 WSDL examples to build a ListGrid that loads data from a web service. I'm able to load the WSDL and the types, set up an input datasource, make the call, see it hit my service, and see the response data in the raw response via the developer's console RPC tab. Summary, I know the round trip request/response is good.

    What I can't do is load the results in a grid; I'm missing something fundamental. Here's the block:
    Code:
     private final String wsOperation = "FindWebDestinations";
     private final String wsdlURL = "http://...."; 
    
     XMLTools.loadWSDL(wsdlURL, new WSDLLoadCallback() {
    
      public void execute(WebService service) {
          if (service == null) {
              SC.warn("WSDL not currently available from A100 (tried " + wsdlURL + ")", new BooleanCallback() {
                  public void execute(Boolean value) {
                  }
              });
              return;
          }
    
          DataSource inputDS = service.getInputDS(wsOperation);
          final DynamicForm form = new DynamicForm();
          form.setNumCols(3);
          form.setWidth(500);
          form.setDataSource(inputDS);
    
          OperationBinding ob = new OperationBinding(DSOperationType.FETCH, wsdlURL);
          ob.setRecordName("destinations");
          ob.setWsOperation(wsOperation);
          ob.setUseFlatFields(true);
    
          DataSource resultsDs = new DataSource();
          resultsDs.setOperationBindings(ob);
          resultsDs.setRecordName("destinations");
          resultsDs.setDataFormat(DSDataFormat.XML);
          resultsDs.setUseFlatFields(true);
          DataSourceField f1 = new DataSourceField("destId", FieldType.INTEGER);
          DataSourceField f2 = new DataSourceField("destName", FieldType.TEXT);
          // f1.setValueXPath("destId");
          // f2.setValueXPath("destName");
          resultsDs.setFields(f1, f2);
          resultsDs = service.getFetchDS(wsOperation, "DestinationSelectType", ob);
    
          final ListGrid destinationsGrid = new ListGrid();
          destinationsGrid.setWidth100();
          destinationsGrid.setDataSource(resultsDs);
    
          IButton fetchButton = new IButton("Fetch");
          fetchButton.addClickHandler(new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                  destinationsGrid.fetchData(form.getValuesAsCriteria());
              }
          });
    
          VLayout layout = new VLayout(20);
          layout.setWidth100();
          layout.setHeight100();
          layout.setLayoutMargin(40);
    
          layout.addMember(form);
          layout.addMember(fetchButton);
          layout.addMember(destinationsGrid);
          canvas.addChild(layout);
    
          SC.clearPrompt();
      }
    }, new RPCRequest(), true);
    This runs as expected. Loads a form with a destId input in which I can place a value and see it in the request. The request:
    Code:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Header/>
        <soap:Body xmlns:ns0="http://www.company.com/ws/CampaignOperations/">
            <ns0:FindWebDestinations>
                <destId>1</destId>
            </ns0:FindWebDestinations>
        </soap:Body>
    </soap:Envelope>
    Here's the soap response:
    Code:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    	<soap:Body>
    		<ns3:FindWebDestinationsResponse xmlns:ns2="http://www.company.com/ws/CampaignManagementTypes" 
    			xmlns:ns3="http://www.company.com/ws/CampaignOperations/">
    			<destinations>
    				<ns2:destId>1</ns2:destId>
    				<ns2:destName>Destination One</ns2:destName>
    			</destinations>
    			<destinations>
    				<ns2:destId>9</ns2:destId>
    				<ns2:destName>Destination 9</ns2:destName>
    			</destinations>
    			<destinations>
    				<ns2:destId>22</ns2:destId>
    				<ns2:destName>Destination Twenty Two</ns2:destName>
    			</destinations>
    		</ns3:FindWebDestinationsResponse>
    	</soap:Body>
    </soap:Envelope>
    If you need the WSDL, I can provide it.

    Thanks, all help is much appreciated.
    Last edited by mdg; 20 Dec 2010, 17:12.

    #2
    You assign the local var "resultDS" to the result of getFetchDS() - this means everything you've set on the DataSource up to that point is not used, only the operationBinding is used (since it's passed to getFetchDS()).

    You either call getFetchDS() to have a DataSource generated for you, or you create the DataSource and link it to the service via the serviceNamespace, but not both.

    As far as why it's not selecting data, enable some of the relevant log categories (xmlSelect for example) to see the XPath being used. At a glance, the recordName you're setting looks wrong. It should be the name of the type, and from your call to getFetchDS(), that's DestinationSelectType and not "destinations".

    Comment

    Working...
    X