You need to sign in to do that
Don't have an account?
Webservice Callout Error
Hi there,
I am trying to call a webservice. But when I am trying to call it gives me an Webservice exception.
global class TestWebService { WebService static string TestWebServiceFetch() { HttpRequest req = new HttpRequest(); string url = 'http://ops.epo.org/soap-services/biblio-retrieval'; req.setEndpoint( url ); req.setMethod('POST'); string envelope ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ops="http://ops.epo.org" xmlns:exc="http://www.epo.org/exchange">' + '<soapenv:Header/>' + '<soapenv:Body>' + '<ops:biblio-retrieval full-publication-cycle="true" xmlns="http://www.epo.org/exchange" xmlns:ops="http://ops.epo.org" >'+ '<publication-reference data-format="epodoc">'+ '<document-id>'+ '<country>EP</country>'+ '<doc-number>EP1000000</doc-number>'+ '<kind>A1</kind>'+ '</document-id>'+ '</publication-reference>'+ '</ops:biblio-retrieval>'+ '</soapenv:Body>'+ '</soapenv:Envelope>'; string parameters = 'country='+EncodingUtil.urlEncode('JP', 'UTF-8')+'&doc-number='+EncodingUtil.urlEncode('3071255', 'UTF-8')+'&kind='+ EncodingUtil.urlEncode('B2', 'UTF-8'); req.setBody(envelope); req.setCompressed(true); req.setHeader('Content-type', 'text/xml;charset=UTF-8'); req.setHeader('Content-length', '538' ); req.setHeader('SOAPAction', 'biblio-retrieval'); req.setHeader('Host','ops.epo.org'); Http http = new Http(); HttpResponse response = http.send(req); system.debug('response.getBody()'+response.getBody()); return response.getBody(); } }
when I hit the request it throws an exception : 'Unable to access envelope'.
Any help will be appreciable.
Tahnks in advance.
Regards,
Bhawani
I am trying to access fedex rate service. I am using the folowing code. BUt in response I get the same envelope which I send. PLease have a look and help.
thanks
public class FedexSoap{
public static String result {set;get;}
// @Future(callout=true)
public static void makeCallout(){
System.Debug('*******Starting Callout*******');
// Instantiate a new http object
Http h = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
//get the Opportunity
//Opportunity opportunity = [Select Id, OwnerId, Name, CloseDate, Probability from Opportunity where Id = :opportunityID];
// The webservice url - Pass in the endpoint to be used using the string url
String url = 'https://gatewaybeta.fedex.com:443/web-services/rate';
String soapXML;
/*soapXML='<?xml version=' + '\''+ '1.0' + '\'' + ' encoding=' + '\''+ 'utf-8' + '\''+'?><SOAP-ENV:Envelope xmlns:SOAP-ENV=' + '\''+ 'http://schemas.xmlsoap.org/soap/envelope/' + '\'' + ' xmlns:SOAP-ENC=' + '\''+'http://schemas.xmlsoap.org/soap/encoding/' + '\'' + ' xmlns:xsi=' + '\''+'http://www.w3.org/2001/XMLSchema-instance' + '\'' + ' xmlns:xsd=' + '\''+' http://www.w3.org/2001/XMLSchema' + '\'' + ' xmlns=' + '\''+'http://fedex.com/ws/ship/v7' + '\'' + '>';
soapXML += '<SOAP-ENV:Body><DeleteTagRequest><WebAuthenticationDetail><UserCredential><Key>8QyzKOB2JN2W4GTc</Key><Password>Rlql9MIEJqzN2Nqcz4qGE6MGq</Password>';
soapXML += '</UserCredential></WebAuthenticationDetail><ClientDetail><AccountNumber>510087224</AccountNumber><MeterNumber>118502046</MeterNumber></ClientDetail>';
soapXML += '<TransactionDetail><CustomerTransactionId>DE_Shakeout_wsvc</CustomerTransactionId></TransactionDetail><Version><ServiceId>ship</ServiceId>';
soapXML += '<Major>7</Major><Intermediate>0</Intermediate><Minor>0</Minor></Version><DispatchLocationId>MQYA</DispatchLocationId><DispatchDate>2008-10-08</DispatchDate><Payment>';
soapXML='<?xml version=' + '\''+ '1.0' + '\'' + ' encoding=' + '\''+ 'utf-8' + '\''+'?><SOAP-ENV:Envelope xmlns:SOAP-ENV=' + '\''+ 'http://schemas.xmlsoap.org/soap/envelope/' + '\'' + ' xmlns:SOAP-ENC=' + '\''+'http://schemas.xmlsoap.org/soap/encoding/' + '\'' + ' xmlns:xsi=' + '\''+'http://www.w3.org/2001/XMLSchema-instance' + '\'' + ' xmlns:xsd=' + '\''+' http://www.w3.org/2001/XMLSchema' + '\'' + ' xmlns=' + '\''+'http://fedex.com/ws/ship/v7' + '\'' + '>'; */
soapXML = '<?xml version=' + '\''+ '1.0' + '\'' + ' encoding=' + '\''+ 'utf-8' + '\''+'?><SOAP-ENV:Envelope xmlns:SOAP-ENV=' + '\''+ 'http://schemas.xmlsoap.org/soap/envelope/' + '\'' + ' xmlns:SOAP-ENC=' + '\''+'http://schemas.xmlsoap.org/soap/encoding/' + '\'' + ' xmlns:xsi=' + '\''+'http://www.w3.org/2001/XMLSchema-instance' + '\'' + ' xmlns:xsd=' + '\''+' http://www.w3.org/2001/XMLSchema' + '\'' + ' xmlns=' + '\''+'http://fedex.com/ws/ship/v7' + '\'' + '>';
soapXML += '<SOAP-ENV:Body><RateRequest><WebAuthenticationDetail><UserCredential><Key>8QyzKOB2JN2W4GTc</Key><Password>Rlql9MIEJqzN2Nqcz4qGE6MGq</Password>';
soapXML += '</UserCredential></WebAuthenticationDetail><ClientDetail><AccountNumber>510087224</AccountNumber><MeterNumber>118502046</MeterNumber></ClientDetail>';
soapXML += '<Shipper><Address><StreetLines>Sender Address Line 1</StreetLines><City>Sender city</City>';
SOAPxml += '<StateOrProvinceCode>TN</StateOrProvinceCode><PostalCode>38115</PostalCode>';
soapXML += '<CountryCode>US</CountryCode></Address></Shipper><Recipient><Address><StreetLines>Recipient Address Line 1</StreetLines>';
soapXML += '<City>Recipient City</City><StateOrProvinceCode>PQ</StateOrProvinceCode><PostalCode>H1E1A1</PostalCode>';
soapXML += '<CountryCode>CA</CountryCode></Address></Recipient><PackagingType>YOUR_PACKAGING</PackagingType>';
soapXML += '</RateRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>';
req.setBody(soapXML);
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-length', '1753' );
req.setHeader('Content-Type', 'text/xml;charset=UTF-8');
req.setHeader('SOAPAction','getRates');
req.setHeader('Host','gatewaybeta.fedex.com');
// Send the request, and return a response
HttpResponse res = h.send(req);
String xml = res.getBody();
result = xml;
//XmlStreamReader r = new XmlStreamReader(xml);
//result = xml; //r.nextTag();
//result = res.getStatus();
//XmlStreamReader xsr = new XmlStreamReader(res);
//xsr.setCoalescing(true);
//xsr.nextTag();
//result = xsr;
}
}
well I have found the solution finally. The problem was with the soap envelope. Here is the correct one.\
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v6="http://fedex.com/ws/rate/v6">
<soapenv:Header/>
<soapenv:Body>
<v6:RateRequest>
<v6:WebAuthenticationDetail>
<v6:UserCredential>
<v6:Key></v6:Key>
<v6:Password></v6:Password>
</v6:UserCredential>
</v6:WebAuthenticationDetail>
<v6:ClientDetail>
<v6:AccountNumber></v6:AccountNumber>
<v6:MeterNumber></v6:MeterNumber>
</v6:ClientDetail>
<v6:Version>
<v6:ServiceId>crs</v6:ServiceId>
<v6:Major>6</v6:Major>
<v6:Intermediate>0</v6:Intermediate>
<v6:Minor>0</v6:Minor>
</v6:Version>
<v6:RequestedShipment>
<v6:Shipper>
<v6:AccountNumber></v6:AccountNumber>
<v6:Contact>
<v6:CompanyName></v6:CompanyName>
<v6:PhoneNumber></v6:PhoneNumber>
</v6:Contact>
<v6:Address>
<v6:StreetLines></v6:StreetLines>
<v6:StreetLines></v6:StreetLines>
<v6:City></v6:City>
<v6:PostalCode></v6:PostalCode>
<v6:CountryCode></v6:CountryCode>
</v6:Address>
</v6:Shipper>
<v6:Recipient>
<v6:Contact>
<v6:PersonName></v6:PersonName>
<v6:CompanyName></v6:CompanyName>
<v6:PhoneNumber></v6:PhoneNumber>
</v6:Contact>
<v6:Address>
<v6:StreetLines></v6:StreetLines>
<v6:StreetLines/>
<v6:City></v6:City>
<v6:StateOrProvinceCode></v6:StateOrProvinceCode>
<v6:PostalCode></v6:PostalCode>
<v6:CountryCode></v6:CountryCode>
</v6:Address>
</v6:Recipient>
<v6:RateRequestTypes>LIST</v6:RateRequestTypes>
<v6:PackageCount>1</v6:PackageCount>
<v6:PackageDetail>INDIVIDUAL_PACKAGES</v6:PackageDetail>
<v6:RequestedPackages>
<v6:SequenceNumber>1</v6:SequenceNumber>
<v6:InsuredValue>
<v6:Currency>USD</v6:Currency>
<v6:Amount>0</v6:Amount>
</v6:InsuredValue>
<v6:Weight>
<v6:Units>KG</v6:Units>
<v6:Value>2.0</v6:Value>
</v6:Weight>
<v6:Dimensions>
<v6:Length>22</v6:Length>
<v6:Width>16</v6:Width>
<v6:Height>17</v6:Height>
<v6:Units>CM</v6:Units>
</v6:Dimensions>
</v6:RequestedPackages>
</v6:RequestedShipment>
</v6:RateRequest>
</soapenv:Body>
</soapenv:Envelope>