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
mauricio.ramos@corpitalmauricio.ramos@corpital 

'No operation available for request' error on ws callout

Hello,

 

I have a button I am trying to use to callout to an external web service but it is giving me a 'No operation available for request' error.  basically I have a custom button with an Execute Javascript behavior. The button code is here:

 

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
sforce.debug.trace=true;

var result = sforce.apex.execute("NAV_Webservice_Functions_MR","sendSO2NAV_buildStream", {pSOId:"{!SCRB_SalesOrder__c.Id}"});

 

The class code is as follows: (i've removed alot of the element additions to the xml stream writer to save space)

 

global class NAV_Webservice_Functions_MR {
    private static SCRB_SalesOrder__c mSO;
    private static List<SCRB_SalesOrderLineItem__c> mSOIs; 

    
// Local method to build Create SO request.
public static void sendSO2NAV_buildStream (String pSOid) {
    string ErrStr;
    string XMLIn;         
    XmlStreamWriter w = new XmlStreamWriter();
    mSO = getSO(pSOid);
    mSOIs = getSOIs(pSOid); 
        w.writeStartDocument(null, '1.0');
        w.writeStartElement(null, 'SendSalesDocumentRequest', null);
        w.writeStartElement(null, 'action', null); 
    //Open main element (Sales Document Info)
    system.debug('### mSO ' + mSO);
        w.writeStartElement(null, 'SalesHeader', null);                      
            AddElementToXMLStream(w,null,'AccountId__c',mSO.AccountId__c,null);                           
            AddElementToXMLStream(w,null,'Currency_Code__c',mSO.Currency_Code__c,null);
            AddElementToXMLStream(w,null,'ShippingStreet__c',mSO.ShippingStreet__c,null);                               
        w.writeEndElement(); //end salesheader
        
    //Open SOIs element holder (inside all SOIs for SO)   
        w.writeStartElement(null, 'SalesLines', null); 
            for(SCRB_SalesOrderLineItem__c soi: mSOIs){
            w.writeStartElement(null, 'SalesLine', null);
            AddElementToXMLStream(w,null,'ProductId__c',soi.ProductId__c,null);
        AddElementToXMLStream(w,null,'Contract_Payment_Start_Date__c',String.valueOf(soi.Contract_Payment_Start_Date__c),null);
            AddElementToXMLStream(w,null,'VAT_Prod_Posting_Group__c',soi.VAT_Prod_Posting_Group__c,null);                                                                                                                                                                                                                                                                          
            //Open SOID elements holder (contacts for SOIs)
            w.writeStartElement(null, 'SalesLineDetails', null);
                for(Sales_Order_Item_Detail__c  soid : [SELECT Id, Name, Sales_Order_Item__c, Contact__c, Contact__r.NAV_Contact_No__c FROM Sales_Order_Item_Detail__c WHERE  Sales_Order_Item__c = : soi.id]) {  
                  w.writeStartElement(null, 'SalesLineDetail', null);
                  AddElementToXMLStream(w,null,'NAV_Contact_No__c',soid.Contact__r.NAV_Contact_No__c,null);
                  w.writeEndElement(); //end saleslinedetail
                }
            w.writeEndElement(); //end saleslinedetails
        w.writeEndElement(); //end salesline   
        }
            w.writeEndElement(); //end saleslines      
        w.writeEndDocument();
        XMLIn = w.getXmlString();
        w.close();  
    //THE ACTUAL METHOD THAT CALLS THE WEB SERVICE IS COMMENTED OUT BUT THE ERROR STILL APPEARS!!!!
    //sendSO2NAV_sendRequest(mSO, XMLIn);   
}


// Web service callout  to send the request. Callback to local methodto process results
 WebService Static void sendSO2NAV_sendRequest(SCRB_SalesOrder__c pSO, String strXML) {
    String xmlresponse = SendNAVSoapDoc(pSO.ERP_Company_Id__c,'wssalesmethods','UpsertSalesDocFromXML_TEST',strXML);         
    //process response from Callout. COMENTED OUT AND REMOVED FROM CLASS TO SAVE SPACE
    //sendSO2NAV_processResponse(xmlresponse);
} 


//////////////////////////////////////////////////////////////////////
    
        public static string SendNAVSoapDoc(string NAVCompanyName, string CUName,string CUFunction,string XMLIn) {
        

        CP_NAVWebservice__c CPSetup = CP_NAVWebservice__c.getInstance('CPSetup');        
        if (NAVCompanyName=='' || NAVCompanyName==null) {NAVCompanyName = CPSetup.NAVWS_Company_Name__c;}
             
        Http http = new Http();
     
        HttpRequest req = new HttpRequest();
     
        req.setMethod('POST');
        req.setEndpoint(CPSetup.Proxy_Base_URL__c + ':' + String.valueOf(Integer.valueOf(CPSetup.Proxy_Port__c)) + '/service');  
        req.setTimeout(Integer.valueOf(CPSetup.Proxy_Timeout_ms__c));  
        Blob headerValue = Blob.valueOf(CPSetup.Proxy_Username__c + ':' + CPSetup.Proxy_Password__c);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-type', 'text/xml; charset="utf-8"');
        req.setHeader('SOAPAction', '"urn:INavWinService/RunNAVCodeunit"');
    
        string SoapDoc = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/>'+
                  '<soapenv:Body><RunNAVCodeunit><NAVWSEndpoint>'+
                  CPSetup.NAVWS_Endpoint__c + NAVCompanyName +'/Codeunit/'+CUName+
                  '</NAVWSEndpoint><CodeunitName>'+CUName+'</CodeunitName>'+
                  '<CodeunitFunction>'+CUFunction+'</CodeunitFunction><XMLIn><![CDATA['+XMLIn+']]></XMLIn>'+
                  '</RunNAVCodeunit></soapenv:Body></soapenv:Envelope>'; 
                  
        req.setbody(SoapDoc);
        System.debug('Trying ' + req.getEndpoint());
        System.debug('Auth Header: ' + req.getHeader('Authorization'));
        System.debug('SOAP Boudy: '+SoapDoc);
        HttpResponse resp = http.send(req);
        System.debug('XML RESPONSE: \n\n' + resp.getBody());           
                  
        return resp.getBody();
    }
     
    
    
    //utility method to add an element to a streamwriter
    public static void AddElementToXMLStream(XmlStreamWriter w, string prefix, string name, string value, string namespaceURI){
        w.writeStartElement(prefix, name, namespaceURI);
        if (value==Null) { value =''; } 
        w.writeCharacters(value);
        w.writeEndElement(); 
    } 

    //Utility methods to get object data from SF. REMOVED MANY FIELDS FROM SOQL FOR SPACE SAVING REASONS IN POST
    public  static List<SCRB_SalesOrderLineItem__c> getSOIs (id pSOId) {
        List<SCRB_SalesOrderLineItem__c> SOItems = new List<SCRB_SalesOrderLineItem__c>();
        SOItems = [SELECT Contract_Manager__c,Contract_Payment_Start_Date__c,Contract_Start_Date__c,Contract_Template__c,
                Contract__Id, Name, Quantity__c  FROM SCRB_SalesOrderLineItem__c WHERE SalesOrderId__c = :pSOId];
        return SOItems; 
    }    
    public static SCRB_SalesOrder__c getSO(id pSOid){
           if(pSOid == null) {
                    mSO = new SCRB_SalesOrder__c() ;                    
           }else{  
                 mSO = [SELECT   Account_PriceBookId__c, AccountId__c, BillingCity__c,BillingCountry__c, BillingFax__c, BillingPhone__c, BillingPostalCode__c, BillingStreet__c, Billing_Account__c, Billing_Contact__c, CreatedById, CreatedDate, CurrencyIsoCode FROM SCRB_SalesOrder__c WHERE id = :pSOid]; 
            }     
            return mSO;
   }
   
   
}

 

This is the trace response I get from the button:

 


<textarea cols=80 rows=5 wrap=hard>
?xml version="1.0" encoding="UTF-8"?

soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
soapenv:Body
soapenv:Fault
faultcode
soapenv:Client
/faultcode

faultstring
No operation available for request {http://soap.sforce.com/schemas/package/NAV_Webservice_Functions_MR}sendSO2NAV_buildStream, please check the WSDL for the service.
/faultstring

/soapenv:Fault
/soapenv:Body
/soapenv:Envelope
</textarea>

 

 

 The callout is broken up in three methods, one to build the request, another to execute it and another to process and parse the results. I've removed some of the processing logic since it is irrelevant at this point (web service is not even being called). I also commented out the actual call to the web service method so the issue is with the button or the method that builds the XML stream. Could the issue be in the URL? Shouldn't it be pointing to the http://soap.sforce.com/schemas/class/NAV_Webservice.....

 

Please assist!!!!! It is urgent!!!!!

Best Answer chosen by Admin (Salesforce Developers) 
mauricio.ramos@corpitalmauricio.ramos@corpital

OK, I just found the solution and will post it for everyone else's edification:

 

The issue was that the sendSO2NAV_buildStream was not visible since I needed to declare that method as a webservice. So I changed the scope from Public to WebService and it worked just fine.