function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jackdjackd 

Noob question: No "login" method for metadata api?

Using apache soap to generate soap clients for the "enterprise" and "metadata" wsdls.


The following works great with the "Enterprise" wsdl::

        binding = (SoapBindingStub) new SforceServiceLocator().getSoap();

        loginResult = binding.login(userName, password);
        binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,
            loginResult.getServerUrl());
        SessionHeader sh = new SessionHeader();
        sh.setSessionId(loginResult.getSessionId());
        binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                          "SessionHeader", sh);
//all subsequent calls work great



However, I must be missing something in the metadata api. There is no "login" method on the MetadataBindingStub generated from the metadata.wsdl ... how does one login and create a session?

            metaBinding = (MetadataBindingStub) new MetadataServiceLocator().getMetadata();
            metaBinding.setUsername(userName);
            metaBinding.setPassword(password);

            metaBinding.describeMetadata(); // >> INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session


Thanks.

SuperfellSuperfell
Use the login call from the enterprise or partner API.
jackdjackd
Thanks for the quick answer. I'm sure I'm missing something obvious. If I do the login with the enterprise api (SoapBindingStub) and then use the resulting loginResult I get a "Invalid Session ID".



        binding = (SoapBindingStub) new SforceServiceLocator().getSoap();

        loginResult = binding.login(userName, password);
        SessionHeader sh = new SessionHeader();
        sh.setSessionId(loginResult.getSessionId());


        metaBinding = (MetadataBindingStub) new MetadataServiceLocator().getMetadata();

        metaBinding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,
        loginResult.getMetadataServerUrl());
        metaBinding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
                               "SessionHeader", sh);
        metaBinding.describeMetadata(); // INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session


I've also tried

        metaBinding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,
                      loginResult.getServerUrl());

and I get

>>  No operation available for request {http://soap.sforce.com/2006/04/metadata}describeMetadata
SuperfellSuperfell
Your using the enterprise namespace when setting the sessionHeader on the metadata stub.
There's a metadataServerUrl on LoginResult to get the url to the metadata API.
jackdjackd
My previous reply maybe wasn't clear:

I mentioned that I've tried both getServerUrl() and getMetadataServerUrl(). I showed the two different error messages depending on which one I use.

Is that what you meant, or is there some other call I should be making?

I appreciate your help. Thanks.




SuperfellSuperfell
binding = (SoapBindingStub) new SforceServiceLocator().getSoap();

loginResult = binding.login(userName, password);
SessionHeader sh = new SessionHeader();
sh.setSessionId(loginResult.getSessionId());


metaBinding = (MetadataBindingStub) new MetadataServiceLocator().getMetadata();

metaBinding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,
loginResult.getMetadataServerUrl());
metaBinding.setHeader(new MetadataServiceLocator().getServiceName().getNamespaceURI(),
"SessionHeader", sh);
metaBinding.describeMetadata();
jackdjackd
Thank you Simon! Here's the complete code in case anyone else finds it helpful:


 public final class Test {

    public static void main(String[] args) {

         String userName = "";
         String password = "";
       
        MetadataServiceLocator metaDataSL = new MetadataServiceLocator();
        SforceServiceLocator salesForceSL = new SforceServiceLocator();
       
       
        try {

            SoapBindingStub soapBinding = (SoapBindingStub) salesForceSL.getSoap();
            soapBinding.setTimeout(60000);
            LoginResult loginResult = soapBinding.login(userName, password);

            SessionHeader sh = new SessionHeader();
            sh.setSessionId(loginResult.getSessionId());

            MetadataBindingStub metaBinding = (MetadataBindingStub) metaDataSL.getMetadata();

            metaBinding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,
                                     loginResult.getMetadataServerUrl());

            metaBinding.setHeader(metaDataSL.getServiceName().getNamespaceURI(),
                                  "SessionHeader", sh);

            System.out.println(metaBinding.describeMetadata());

           
        } catch (Exception e) {
            e.printStackTrace();
        }
       

    }

}


UmarUmar

the above code was very helpful...

 

i am facing the following issue when i use the delete method of metadata...

 

metadatabinding.delete(plMetadata); ----> java.io.IOException: No serializer found for class com.sforce.soap.enterprise.SessionHeader in registry org.apache.axis.encoding.TypeMappingDelegate@1eb8f6d

 

code used for binding:::

 

SessionHeader sessionHeader = new SessionHeader();
sessionHeader.setSessionId(loginResult.getSessionId());
            
SforceServiceStub stub = new SforceServiceStub(loginResult.getServerUrl());
log.info("Connected to SF with the URL: " + endPointURL);
            
metadatabinding = (MetadataBindingStub) new MetadataServiceLocator().getMetadata();
metadatabinding._setProperty(MetadataBindingStub.ENDPOINT_ADDRESS_PROPERTY,                         loginResult.getMetadataServerUrl());
metadatabinding.setHeader(new MetadataServiceLocator().getServiceName().getNamespaceURI(),
                    "SessionHeader", sessionHeader);

 

metadatabinding.delete(plMetadata); ----> java.io.IOException: No serializer found for class com.sforce.soap.enterprise.SessionHeader in registry org.apache.axis.encoding.TypeMappingDelegate@1eb8f6d

 

TIA :) ,

Umar

 

 

 

SuperfellSuperfell

You need to use the SessionHeader class from the metadata wsdl/package, you're using the one from the enterprise wsdl/package.

LuckkyLuckky

Hi 

 

I have a problem .

 

I generate metadata.jar and enterprise.jar  from Wsc-20.jar .But these jars do not contain  

 

MetadabindingStub,

MetadataServiceLocator,

SoapBindingStub

SforceServiceLocator

SessionHeader  classes . How can I get these Clases .

 

Please Help me its urgent...............................