Start of Content Area

Background documentation Code Example for Web Service Call (Eclipse Web Tools Platform)  Locate the document in its SAP Library structure

Using the following example code you can create a simple object of type Party (communication party). Use the Web Service client that you created using the Eclipse Web Tools Platform.

package CommunicationPartyServiceWsd;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import demo.types.ConfigurationObjectModifyOut;

import demo.types.PartyCreateChangeIn;

import demo.types.PartyRestricted;

 

public class CallMe {

  public static void main(String[] args) {

    try{

      //Create a new simple Communication Party and set mandatory attributes

      PartyRestricted party = new PartyRestricted();

      party.setMasterLanguage("en");

      party.setPartyID("HelloWorld");

 

      //Create a new instance of request object expected by Communication

      //Party Web Service and set the above created object instance

      PartyCreateChangeIn partyCreateRequest = new PartyCreateChangeIn();    

      partyCreateRequest.setParty(new PartyRestricted[]{party});

     

      //Create a new service instance and fetch the port type instance, ...

      HTTPService service = new HTTPServiceLocator();

      CommunicationPartyServiceVi_Document document = service.getHTTPort();

     

      // ... cast it to a stub instance and set user/password because basic authentication is

      // required by Web Service

      HTTPBindingStub stub =  (HTTPBindingStub) document;

      stub.setUsername("myuser");

      stub.setPassword("mypwd");

     

      //Now call the Web Service and create the HelloWorld Communication Party

      ConfigurationObjectModifyOut response = document.create(partyCreateRequest);

     

      //Do something with the response

      System.out.println( response.toString() );

    } catch (RemoteException ex){

      ex.printStackTrace();     

    } catch (ServiceException e) {

      e.printStackTrace();

    }

  }

}

 

End of Content Area