You need to sign in to do that
Don't have an account?
Charlie1
Web service callout failed: Unexpected element. Parser was expecting element 'urn:server:helloResponse' but found ':helloResponse'
I am trying to test a web service callout from Salesforce to a PHP web service but I am getting this error and I am struggling to find a solution.
This is the WSDL file (http://www.popo.it/WebServiceSOAP/server.php?wsdl) that has been imported in SF with WSDL2APEX.
The generated class is
//Generated by wsdl2apex
public class wsexample {
public class helloRequestType {
public String name;
private String[] name_type_info = new String[]{'name','urn:server',null,'1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
private String[] field_order_type_info = new String[]{'name'};
}
public class wsexamplePort {
public String endpoint_x = 'http://www.popo.it/WebServiceSOAP/server.php';
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[]{'urn:server', 'wsexample'};
public String hello(String name) {
wsexample.helloRequestType request_x = new wsexample.helloRequestType();
wsexample.helloResponseType response_x;
request_x.name = name;
Map<String, wsexample.helloResponseType> response_map_x = new Map<String, wsexample.helloResponseType>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'urn:server#hello',
'urn:server',
'hello',
'urn:server',
'helloResponse',
'wsexample.helloResponseType'}
);
response_x = response_map_x.get('response_x');
return response_x.return_x;
}
}
public class helloResponseType {
public String return_x;
private String[] return_x_type_info = new String[]{'return','urn:server',null,'1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
private String[] field_order_type_info = new String[]{'return_x'};
}
}
And the VF page using it is
<apex:page controller="WSContoller" tabStyle="Account">
It will be a nice to get output from the controller
<p>My webservice is now returning {!HelloWorld} !!</p>
</apex:page>
with controller
public class WSContoller {
public String helloWorld;
public String getHelloWorld() {
string MyReturn;
wsexample.wsexamplePort stub = new wsexample.wsexamplePort();
MyReturn = stub.hello('Nicola');
return MyReturn ;
}
}
The response from the WS tested in SoapClient.com is
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<helloResponse>
<great>Hello, Nicola!</great>
</helloResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Please, can you help me to find the error?
This is the WSDL file (http://www.popo.it/WebServiceSOAP/server.php?wsdl) that has been imported in SF with WSDL2APEX.
The generated class is
//Generated by wsdl2apex
public class wsexample {
public class helloRequestType {
public String name;
private String[] name_type_info = new String[]{'name','urn:server',null,'1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
private String[] field_order_type_info = new String[]{'name'};
}
public class wsexamplePort {
public String endpoint_x = 'http://www.popo.it/WebServiceSOAP/server.php';
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[]{'urn:server', 'wsexample'};
public String hello(String name) {
wsexample.helloRequestType request_x = new wsexample.helloRequestType();
wsexample.helloResponseType response_x;
request_x.name = name;
Map<String, wsexample.helloResponseType> response_map_x = new Map<String, wsexample.helloResponseType>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'urn:server#hello',
'urn:server',
'hello',
'urn:server',
'helloResponse',
'wsexample.helloResponseType'}
);
response_x = response_map_x.get('response_x');
return response_x.return_x;
}
}
public class helloResponseType {
public String return_x;
private String[] return_x_type_info = new String[]{'return','urn:server',null,'1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
private String[] field_order_type_info = new String[]{'return_x'};
}
}
And the VF page using it is
<apex:page controller="WSContoller" tabStyle="Account">
It will be a nice to get output from the controller
<p>My webservice is now returning {!HelloWorld} !!</p>
</apex:page>
with controller
public class WSContoller {
public String helloWorld;
public String getHelloWorld() {
string MyReturn;
wsexample.wsexamplePort stub = new wsexample.wsexamplePort();
MyReturn = stub.hello('Nicola');
return MyReturn ;
}
}
The response from the WS tested in SoapClient.com is
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<helloResponse>
<great>Hello, Nicola!</great>
</helloResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Please, can you help me to find the error?
Please check following things:
1) Webservice endpoint URL is added to the Remote Site Settings in Salesforce
2) Salesforce IP range are white listed.
3) What are you getting in Debug logs?
The most likely cause of the error , is the webservice that you are trying to call is throwing an exception.
Its most likely a webservice built using .NET framework.
above method refers a html page reference from which you are extracting your input data.You are forming your input request in html format while your webservice is expectng soap envelope. I think you need to wrap or convet or edit your request, formed in above method as soap envelope, then only your server accept it.
Also the end point url, seems to be incorrect, its pointing to localhost, it should have the server IP or name.
See the discussion threads as well,
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009By5IAE
Regards,
Ashish
To do this, you would replace all the 'urn:server' with ''
I'll be interested to see how it goes.