You need to sign in to do that
Don't have an account?
ziros
Apex class: calling webservice with args as xml
Hello, I have the next simple scenario:
scontrol which calls an apex class that calls ASP.NET webservice as the following :
(all is working fine)
global class WSIchlusSalesForceHelper
{
global class ContactIchlus
{
webservice String ContactRole;
webservice String BirthDate;
{
global class ContactIchlus
{
webservice String ContactRole;
webservice String BirthDate;
webservice String arg1;
webservice String arg2;
webservice String arg3;
webservice String arg4;
...
webservice String arg2;
webservice String arg3;
webservice String arg4;
...
...
}
}
WebService static string test1(ContactIchlus data)
{
WSIchlusSalesForce.ServiceIchlusSoap soap = new WSIchlusSalesForce.ServiceIchlusSoap();
return soap.IchlusProtocol(data.BirthDate);
}
}
{
WSIchlusSalesForce.ServiceIchlusSoap soap = new WSIchlusSalesForce.ServiceIchlusSoap();
return soap.IchlusProtocol(data.BirthDate);
}
}
My question is,
In the inner class ContactIchlus which will have at least 20 variables or more, that I need to pass to the webservice...
I can't just pass the variable data...
Is there a simple way to convert that inner class to XML and pass it to the webservice ?
or I will have to concat string and build the xml myself ?
or maybe I will have to define 20 args to the webservice
TIA (it's my first webservice)
Construct an object type on the .NET side of things that will have all these properties.
Pass the web service an argument of that object type.
Take your new WSDL and generate the Apex classes and you should see an equivalent (inner) class being generated there.
Just create an instance of it, set all the variables and pass that to your web service.
Hope this helps,
David
David / Others
I do have a problem here , hope you can help
I created a class in asp.net and it generate as you said an inner class within the generated apex class from wsdl
so now this is the part within the generated apex class:
public class ContactIchlus {
public DateTime BirthDate;
public String ContactRole;
public Integer DistrictCode;
private String[] BirthDate_type_info = new String[]{'BirthDate','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
private String[] ContactRole_type_info = new String[]{'ContactRole','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] DistrictCode_type_info = new String[]{'DistrictCode','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://tempuri.org/','true'};
private String[] field_order_type_info = new String[]{'BirthDate','ContactRole','DistrictCode'};
}
and this is my apex class which uses it
global class WSIchlusSalesForceHelper
{
WebService static string test1(WSIchlusSalesForce.ContactIchlus data)
{
WSIchlusSalesForce.ServiceIchlusSoap soap = new WSIchlusSalesForce.ServiceIchlusSoap();
return soap.IchlusProtocol(data.BirthDate);
}
}
The error I'm getting on my class is
Error: Compile Error: Argument type of global method must also be global: WSIchlusSalesForce.ContactIchlus at line 9 column 30
becuase my class calls a webservice it needs the Global declaration... but in the generated class from wsdl the inner class is not global... how to overcome this....
TIA
It's only when your own class needs to be exposed as a webservice that it needs to be global. Not when you're calling a webservice.
Your not creating a webservice on Salesforce.com just for calling another .NET webservice right ?
David
data.BirthDate = '{!Contact.Birthdate}';
That's because you put the 'Webservice' keyword in your method. You don't need to do that.
The Webservice keyword is when you want to expose your Apex method as a webservice. If I understand correctly, that's not what you want to do. You just want to *call* an external .NET webservice right ?
The .NET webservice is the 'server' and the Apex class needs to be the 'client'. Can you confirm that ?
David
I am not much help here since I am having the exact same problem (different wsdl - but same arrangement).
I don't know if the OP chose the webservice keyword, but I choose it because I am reading from the cookbook example "Sending messages from Apex" and thats the way the example is setup. Unfortunately it doesn't work for my wsdl either.
If I understand the example in the book right, they are suggesting you create the webservice that calls the webservice so it can be used in any S-Control through the ajax toolkit with apex.execute.
Are you saying skip this and put it directly in the S-Control?
OK, it just dawned on me (that's the difference between late at night and early morning : sleeping always reboots my brain :smileywink: ) : you're coming from an S-Control ... that's why you went the Apex web service route ...
So it's : S-Control -> Apex Webservice -> .NET Webservice right ?
Couldn't you just use a VF page + controller to do what you're doing ? ... today VF is more or less favored over using S-Controls (and if you ask me, it's much easier to do too).
Anyway : You've got this far already so you might want to try this first : in the wsdl2apex generated class, modify the access modifiers from 'public' to 'global' for your inner classes/methods... that will bring this class and it's members in the global scope and might help you get rid of the 'Argument type of global method must also be global: ' message.
Hang in there, you'll get it working !
David
Exactly this is the current route - S-Control -> Apex Webservice -> .NET Webservice
and compilation went through, just have to check it now for completion.
any help will be appriciated