SOAP API

SERVICE SIDE
1.       Write the webService class
global class myServiceAccInsert{
    webservice static void AccInsert(Account objA){
        insert objA;
    }
}
2.        Generate Partner WSDL and webService class WSDL to pass to CLIENT
CLIENT SIDE
1.       Generate Classes from both WSDLs received from the Service Side.
a)  sobjectPartnerSoapSforceCom - urn:sobject.partner.soap.sforce.com (WSDL Namespace)
b)  faultPartnerSoapSforceCom - urn:fault.partner.soap.sforce.com (WSDL Namespace)
c)  partnerSoapSforceCom - urn:partner.soap.sforce.com (WSDL Namespace)
d)  soapClassWithWebservice - http://soap.sforce.com/schemas/class/classWithWebService (Namespace)
2. Reduce code if the classes generated are two long - remove all unwanted Complextypes.
IMPORTANT: Maximum number of characters in a class are 1Million
      If there is 'AnyType' Error in WSDL replace 'Any Type' with 'String'.
2.       Write the following Page and Page Controller and configure login uesrname, password.
Page:
<apex:page controller="testSOAPController">
  <apex:form >
      <apex:pageblock >
        <apex:pageblocksection >
            <apex:inputfield value="{!objA.Name}"/>
        </apex:pageblocksection>     
        <apex:commandButton value="Save" action="{!doSave}" style="margin-left:20%;"/>
      </apex:pageblock>
  </apex:form>
</apex:page>
Page Controller:
public with sharing class testSOAPController {
    public PageReference doSave() {
        partnerSoapSforceCom.Soap myPartnerSoap = new partnerSoapSforceCom.Soap();

        partnerSoapSforceCom.LoginResult partnerLoginResult = myPartnerSoap.login('sfdc.gsk@gmail.com', '********');

        soaptosfdcgsk.SessionHeader_element webserviceSessionHeader = new soaptosfdcgsk.SessionHeader_element();

        webserviceSessionHeader.sessionId = partnerLoginResult.sessionId;

        soaptosfdcgsk.myServiceAccInsert    myWebservice = new soaptosfdcgsk.myServiceAccInsert();

        myWebservice.SessionHeader = webserviceSessionHeader;
       
        soaptosfdcgsk.Account sA = new soaptosfdcgsk.Account();
        sA.Name = objA.Name;
        myWebservice.AccInsert(sA);
        insert objA;
        return (new pagereference('/apex/testSOAP').setredirect(true));
    }

  public Account objA{get;set;}
    public testSOAPController (){
        objA = new Account();
    }
}

Flow 
Web service à WSDL file (define the Web Service) à API (Platform use WSDL to generate API)

WSDL file is required to access Force.com Web Service. It defines the web service that is available.

For downloading WSDL à login as administrator or as a user who has the “Modify all Data” permission.

From Setup, click Develop | API to display the WSDL download page 

The WSDL file is dynamically generated based on which type of WSDL file (enterprise or partner) you download.

·        Force.com Enterprise WSDL—This API is for most enterprise users who are developing client applications for their organization. The enterprise WSDL file is a strongly typed representation of your organization’s data. It provides information about your schema, data types, and fields to your development environment, allowing for a tighter integration between it and the Force.com Web service. This WSDL changes if custom fields or custom objects are added to, renamed, or removed from, your organization’s Salesforce configuration. If you are downloading an enterprise WSDL and you have managed packages installed in your organization, you need to take an extra step to select the version of each installed package to include in the generated WSDL.
Note the following when generating the enterprise WSDL:
o    If new custom fields or objects are added to, renamed, or removed from your organization’s information, you need to regenerate the WSDL file in order to access them.
o    The generated WSDL contains the objects and fields in your organization, including those available in the selected versions of each installed package. If a field or object is added in a later package version, you must generate the enterprise WSDL with that package version to work with the object or field in your API integration.
·        Force.com Partner WSDL—This API is for salesforce.com partners who are developing client applications for multiple organizations. As a loosely-typed representation of the Salesforce object model, the partner WSDL can be used to access data within any organization.




Enterprise WSDL
Partner WSDL
Strongly typed, the object and its attributes are fixed.
Is loosely typed, the object and its attributes can be variable.
Contains the metadata about all standard and custom fields and objects.
Does not contain metadata about objects and fields. Takes an array of key-value pairs.
Can only be used against your Salesforce instance.
Can be used against many Salesforce.com organizations.

Simple Object Access Protocol (SOAP)

Web Service Description Language (WSDL)


Comments

Popular posts