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
Gaurav AgnihotriGaurav Agnihotri 

call to external WebService failing (statuscode 404)

Hi All, 
I am trying to connect to external webservice. I am using Jeff Dougloas blog as referencehttp://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/

I created a new remote site.
Below is the class:
public class WebServiceCallout {

    //@future (callout=true)
    public static void sendNotification(String territories, String searchText) {

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('https://pelcosales.schneider-electric.com/Administration/SalesForceServices');
        req.setMethod('POST');
        req.setBody('territories='+EncodingUtil.urlEncode(territories, 'UTF-8')+'&searchText='+EncodingUtil.urlEncode(searchText, 'UTF-8'));
        //req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
            System.debug(res.toString());
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }

    }

    // run WebServiceCallout.testMe(); from Execute Anonymous to test
    /*public static testMethod void testMe() {
        WebServiceCallout.sendNotification('My Test Customer','My City');
    }*/

}

I am executing it by running following code in Execute Anonymous Window
WebServiceCallout.sendNotification('17','360 Advanced Security Corporation');
I am getting error message :
15:36:13:427 USER_DEBUG [17]|DEBUG|System.HttpResponse[Status=Not Found, StatusCode=404]

I would appreciate any help.
 
Best Answer chosen by Gaurav Agnihotri
Daniel BallingerDaniel Ballinger

Gaurav, I made an alternative version of Wsdl2Apex and presented it at Dreamforce '14 - Improved Apex support for SOAP based web services (http://http://www.fishofprey.com/2014/11/dreamforce-2014-presentation-improved.html). It offers improved support for certain WSDL features and can ignore irrelevant features (like extra ports).

Good luck!

All Answers

KrForceKrForce
Did you add the remote site setting for the call out URL? if not then try after adding.
Gaurav AgnihotriGaurav Agnihotri
I did added a remote site
Remote Site
KrForceKrForce
I tried with Http im getting "Status=Internal Server Error, StatusCode=500" exception and i guess it could be because your legacy Application is not allowing the request from salesforce.Your provider needs to whiteliste the SFDC IPs then only you should be able to make the call out from salesforce.

User-added image
Daniel BallingerDaniel Ballinger
Are you sure the web service is listening to POST requests to https://pelcosales.schneider-electric.com/Administration/SalesForceServices ?

I tried posting the body:
territories=17&searchText=360%20Advanced%20Security%20Corporation
to that URL and got a 404 response back from the web server. 

It seems more like the web service isn't at that URL.
Gaurav AgnihotriGaurav Agnihotri
Thanks Daniel and AKRM07. Both of you are right. The webeservice is not listening at the URL. I am still woking with webservice developer. It seems like I will have to create Apex classes by importing WSDL.
Wish me luck :(
Daniel BallingerDaniel Ballinger

Gaurav, I made an alternative version of Wsdl2Apex and presented it at Dreamforce '14 - Improved Apex support for SOAP based web services (http://http://www.fishofprey.com/2014/11/dreamforce-2014-presentation-improved.html). It offers improved support for certain WSDL features and can ignore irrelevant features (like extra ports).

Good luck!

This was selected as the best answer
Gaurav AgnihotriGaurav Agnihotri
Hi Daniel, 
Thanksfor the information. I downloaded WSDL2Apex. Amazing tool... However, I am still getting error message when I deploy apex class public class tempuriOrg .

Error: Apex Classes were not deployed. Original error:

Error StatusCode:INVALID_FIELD_FOR_INSERT_UPDATE
Failed to save 1 new sObject(s)

0:Error  INVALID_FIELD_FOR_INSERT_UPDATE - Invalid type: schemasDatacontractOrg200407PelcoSa.ArrayOfCompanyModel
Successfully saved 0 records.

Data:
Operation: Deployed
Gaurav AgnihotriGaurav Agnihotri
Hi Daniel,
Here is WSDL file
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="PartnerAdvantageService" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<wsdl:types>
		<xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
			<xs:import namespace="http://schemas.datacontract.org/2004/07/Pelco.SalesForce.WcfServices.PartnerAdvantage"/>
			<xs:element name="FindCompanies">
				<xs:complexType>
					<xs:sequence>
						<xs:element minOccurs="0" name="territories" nillable="true" type="xs:string"/>
						<xs:element minOccurs="0" name="searchText" nillable="true" type="xs:string"/>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
			<xs:element name="FindCompaniesResponse">
				<xs:complexType>
					<xs:sequence>
						<xs:element minOccurs="0" name="FindCompaniesResult" nillable="true" type="q1:ArrayOfCompanyModel" xmlns:q1="http://schemas.datacontract.org/2004/07/Pelco.SalesForce.WcfServices.PartnerAdvantage"/>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:schema>
		<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/">
			<xs:element name="anyType" nillable="true" type="xs:anyType"/>
			<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
			<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
			<xs:element name="boolean" nillable="true" type="xs:boolean"/>
			<xs:element name="byte" nillable="true" type="xs:byte"/>
			<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
			<xs:element name="decimal" nillable="true" type="xs:decimal"/>
			<xs:element name="double" nillable="true" type="xs:double"/>
			<xs:element name="float" nillable="true" type="xs:float"/>
			<xs:element name="int" nillable="true" type="xs:int"/>
			<xs:element name="long" nillable="true" type="xs:long"/>
			<xs:element name="QName" nillable="true" type="xs:QName"/>
			<xs:element name="short" nillable="true" type="xs:short"/>
			<xs:element name="string" nillable="true" type="xs:string"/>
			<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
			<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
			<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
			<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
			<xs:element name="char" nillable="true" type="tns:char"/>
			<xs:simpleType name="char">
				<xs:restriction base="xs:int"/>
			</xs:simpleType>
			<xs:element name="duration" nillable="true" type="tns:duration"/>
			<xs:simpleType name="duration">
				<xs:restriction base="xs:duration">
					<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
					<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
					<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
				</xs:restriction>
			</xs:simpleType>
			<xs:element name="guid" nillable="true" type="tns:guid"/>
			<xs:simpleType name="guid">
				<xs:restriction base="xs:string">
					<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
				</xs:restriction>
			</xs:simpleType>
			<xs:attribute name="FactoryType" type="xs:QName"/>
			<xs:attribute name="Id" type="xs:ID"/>
			<xs:attribute name="Ref" type="xs:IDREF"/>
		</xs:schema>
		<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Pelco.SalesForce.WcfServices.PartnerAdvantage" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/Pelco.SalesForce.WcfServices.PartnerAdvantage">
			<xs:complexType name="ArrayOfCompanyModel">
				<xs:sequence>
					<xs:element minOccurs="0" maxOccurs="unbounded" name="CompanyModel" nillable="true" type="tns:CompanyModel"/>
				</xs:sequence>
			</xs:complexType>
			<xs:element name="ArrayOfCompanyModel" nillable="true" type="tns:ArrayOfCompanyModel"/>
			<xs:complexType name="CompanyModel">
				<xs:sequence>
					<xs:element minOccurs="0" name="Address1" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="City" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="CompanyName" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="Country" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="CustomerNumber" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="DateSubmitted" type="xs:dateTime"/>
					<xs:element minOccurs="0" name="PartnerID" type="xs:int"/>
					<xs:element minOccurs="0" name="PartnerLevelDate" type="xs:dateTime"/>
					<xs:element minOccurs="0" name="PartnerLevelName" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="Phone" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="PostalCode" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="ProfileStatus" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="RepFirmName" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="State" nillable="true" type="xs:string"/>
					<xs:element minOccurs="0" name="StatusDate" type="xs:dateTime"/>
					<xs:element minOccurs="0" name="TermsConditionsDate" type="xs:dateTime"/>
					<xs:element minOccurs="0" name="Territory" type="xs:unsignedByte"/>
				</xs:sequence>
			</xs:complexType>
			<xs:element name="CompanyModel" nillable="true" type="tns:CompanyModel"/>
		</xs:schema>
	</wsdl:types>
	<wsdl:message name="IPartnerAdvantageService_FindCompanies_InputMessage">
		<wsdl:part name="parameters" element="tns:FindCompanies"/>
	</wsdl:message>
	<wsdl:message name="IPartnerAdvantageService_FindCompanies_OutputMessage">
		<wsdl:part name="parameters" element="tns:FindCompaniesResponse"/>
	</wsdl:message>
	<wsdl:portType name="IPartnerAdvantageService">
		<wsdl:operation name="FindCompanies">
			<wsdl:input wsaw:Action="http://tempuri.org/IPartnerAdvantageService/FindCompanies" message="tns:IPartnerAdvantageService_FindCompanies_InputMessage"/>
			<wsdl:output wsaw:Action="http://tempuri.org/IPartnerAdvantageService/FindCompaniesResponse" message="tns:IPartnerAdvantageService_FindCompanies_OutputMessage"/>
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="BasicHttpBinding_IPartnerAdvantageService" type="tns:IPartnerAdvantageService">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
		<wsdl:operation name="FindCompanies">
			<soap:operation soapAction="http://tempuri.org/IPartnerAdvantageService/FindCompanies" style="document"/>
			<wsdl:input>
				<soap:body use="literal"/>
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal"/>
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="PartnerAdvantageService">
		<wsdl:port name="BasicHttpBinding_IPartnerAdvantageService" binding="tns:BasicHttpBinding_IPartnerAdvantageService">
			<soap:address location="http://pelcosales.schneider-electric.com/PartnerAdvantage/PartnerAdvantageService.svc"/>
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

 
Daniel BallingerDaniel Ballinger

Hi Gaurav,

I was able to deploy the generated apex classes from the WSDL using our FuseIT tool.

Make sure you are either using the "Deploy All Apex Classes to Salesforce" button or that you deploy the schemasDatacontractOrg200407PelcoSa class first. It will have it's own tab next to tempUrlOrg (assuming you haven't renamed the namespace to class name mapping.

I saw the two error reports you submitted. Are you still having issues with WebServiceCallout.invoke?

Regards,
Daniel

Gaurav AgnihotriGaurav Agnihotri
Hi Daniel, 
I am still having issues. I am using version v2.9.0.143. I am deploying it in sandbox.

Error: Compile Error: Method does not exist or incorrect signature: WebServiceCallout.invoke(tempuriOrg.BasicHttpBinding_IPartnerAdvantageService, tempuriOrg.FindCompanies_element, Map<String,tempuriOrg.FindCompaniesResponse_element>, List<String>) at line 22 column 13 i.e.
WebServiceCallout.invoke(

 
//Generated by FuseIT WSDL2Apex (http://www.fuseit.com/Solutions/SFDC-Explorer/Help-WSDL-Parser.aspx)
//Methods Included: FindCompanies
// Primary Port Class Name: BasicHttpBinding_IPartnerAdvantageService   
public class tempuriOrg {
    public class BasicHttpBinding_IPartnerAdvantageService {
        public String endpoint_x = 'http://pelcosales.schneider-electric.com/PartnerAdvantage/PartnerAdvantageService.svc';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://tempuri.org/','tempuriOrg','http://schemas.microsoft.com/2003/10/Serialization/','schemasMicrosoftCom200310Serializat','http://schemas.datacontract.org/2004/07/Pelco.SalesForce.WcfServices.PartnerAdvantage','schemasDatacontractOrg200407PelcoSa'};

        public schemasDatacontractOrg200407PelcoSa.ArrayOfCompanyModel FindCompanies(String territories,String searchText) {
            tempuriOrg.FindCompanies_element request_x = new tempuriOrg.FindCompanies_element();
            tempuriOrg.FindCompaniesResponse_element response_x;
            request_x.territories = territories;
            request_x.searchText = searchText;
            Map<String, tempuriOrg.FindCompaniesResponse_element> response_map_x = new Map<String, tempuriOrg.FindCompaniesResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                'http://tempuri.org/IPartnerAdvantageService/FindCompanies',
                'http://tempuri.org/',
                'FindCompanies',
                'http://tempuri.org/',
                'FindCompaniesResponse',
                'tempuriOrg.FindCompaniesResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.FindCompaniesResult;
        }
    }
    public class FindCompanies_element {
        public String territories;
        public String searchText;
        private String[] territories_type_info = new String[]{'territories','http://tempuri.org/','string','0','1','true'};
        private String[] searchText_type_info = new String[]{'searchText','http://tempuri.org/','string','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
        private String[] field_order_type_info = new String[]{'territories','searchText'};
    }
    public class FindCompaniesResponse_element {
        public schemasDatacontractOrg200407PelcoSa.ArrayOfCompanyModel FindCompaniesResult;
        private String[] FindCompaniesResult_type_info = new String[]{'FindCompaniesResult','http://tempuri.org/','ArrayOfCompanyModel','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true','false'};
        private String[] field_order_type_info = new String[]{'FindCompaniesResult'};
    }
}

 
Daniel BallingerDaniel Ballinger
I think I've isolated the problem. You have your own class called WebServiceCallout. This is obscuring the built in class with the same name. Hence it can't find the invoke method with the expected signature.

Try renaming your existing WebServiceCallout class to something else before saving the Wsdl2Apex output.
Gaurav AgnihotriGaurav Agnihotri
Yes!!!
That did solve the problem. Thankyou Daniel!!! you are the man!!!
 
TarakkumarTarakkumar
Hi Daniel,
Is the xsd.attribute supported in WebServiceCallout.invoke method? It seems the XML is not generated properly when there is an attribute associated with a complex type.
Daniel BallingerDaniel Ballinger
Tarakkumar, there is limited support for xsd:attribute. It really depends on the schema. Maybe you want to start a new question and provide some additional details.