Forum Discussion

irxn's avatar
irxn
Occasional Contributor
10 years ago

How to get parameter of SOAP operation

HI,   I want to read the methods of a webservice and show the user the methods and parameters in java. This is my code so far:   WsdlProject project = new WsdlProject(); WsdlInterface iface = W...
  • rupert_anderson's avatar
    10 years ago

    Hi Peter,

     

    I had a quick look and say you have a WSDL with operation defined like:

     

    ...

    <message name="GetInvoiceRequestMessage">
    <part name="invoiceRef" element="inv:getInvoice"></part>
    </message>
    <message name="GetInvoiceResponseMessage">
    <part name="invoiceDocument" element="inv:InvoiceDocument"></part>
    </message>
    <portType name="InvoicePortType">
    <documentation>Get An Invoice Using It's Invoice Number
    </documentation>
    <operation name="getInvoice">
    <input name="GetInvoiceInput" message="tns:GetInvoiceRequestMessage"/>
    <output name="GetInvoiceOutput" message="tns:GetInvoiceResponseMessage"/>
    </operation>
    </portType>
    <binding name="InvoicePortBinding" type="tns:InvoicePortType">
    <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="getInvoice">
    <soap:operation
    soapAction="http://soapui.cookbook.samples/getInvoiceRequest/request" />
    <input name="GetInvoiceInput">
    <soap:body use="literal" />
    </input>
    <output name="GetInvoiceOutput">
    <soap:body use="literal" />
    </output>
    </operation>
    </binding>

    ...

     

    Then adding these lines of code to your code's while loop:

     

    while (i.hasNext()) {

     op = (WsdlOperation) i.next();

     System.out.println("Operation: " + op.getName());

     MessagePart[] messageParts = op.getDefaultRequestParts();

     System.out.println("Request Message Part Name: "+messageParts[0].getName());

     System.out.println("Request Message Part Type: "+messageParts[0].getPartType());

     System.out.println("Request Message Part Description: "+messageParts[0].getDescription());

    }

     

    Gives output:

     

    Operation: getInvoice

    Request Message Part Name: invoiceRef

    Request Message Part Type: CONTENT

    Request Message Part Description: invoiceRef of type [{http://soapui.cookbook.samples/schema/invoice}InvoiceRefType]

     

    Is this something like what you want?

     

    Note, if you actually wanted the request, this can be generated by adding the following lines:

     

    WsdlOperation operation = (WsdlOperation) iface.getOperationByName( "getInvoice" );

    WsdlRequest request = operation.addNewRequest( "getInvoice Request" );

    System.out.println("Request String Content: "+operation.createRequest( true ).toString());

     

    Gives:

     

    Request String Content: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inv="http://soapui.cookbook.samples/schema/invoice">

       <soapenv:Header/>

       <soapenv:Body>

          <inv:getInvoice>

             <inv:invoiceNo>?</inv:invoiceNo>

          </inv:getInvoice>

       </soapenv:Body>

     

    Hope this helps,

    Cheers,

    Rup