Wednesday, June 15, 2005

The Code Project - Publish, Discover and Invoke Web Services using SOAP and UDDI - C# WebServices

The Code Project - Publish, Discover and Invoke Web Services using SOAP and UDDI - C# WebServices: "Invoking the web service: Now we'll invoke the web service method using the SOAP SDK provided by Microsoft. Invoking services using SoapClient(n) class is fairly easy. Here n means the major version appended to the classes. this number is not associated with SOAP SDK's previous versions than 3.0. MSSoapInit method in SoapClient(n) class initialises the web service for the given WSDL and accepts service name and service port.

private void invoke_Click(object sender, System.EventArgs e))
{
SoapClient30 sc = new SoapClient30();
string translateText=textToTran.Text;
string wsdl=null;
try
{
if(wsUri==null)
throw new Exception('Please Discover the service first');
if((new Regex('(wsdl)$')).IsMatch(wsUri))
//check if it's the real WSDL
wsdl=wsUri;
else
wsdl=wsUri+'?wsdl'; //otherwise append WSDL to the service

sc.MSSoapInit(wsdl, 'piglatin', 'piglatinSoap','');
//specify the service name and port name
Type type =sc.GetType();

object []args = {translateText}; //specified service accepts
//just one argument (textToTranslate)
Response.Write('Invoking method using MS SOAP SDK ...');
object ox = type.InvokeMember('toPigLatin',
BindingFlags.InvokeMethod,null,sc,args); //Dynamic Invocation No
//Proxy class, no web reference
Response.Write('Translated String '+ox.ToString());
}
catch(Exception sEx){Response.Write('Exception occurred '+
sEx.Message);}}}"
Post a Comment