Advertisement

03.06.2008 at 01:20PM PST, ID: 23221141
[x]
Attachment Details

Dynamically invoke a web service method wiith  (URL with IP, Service Name, Port, Namespace)

Asked by Jzzzz in Microsoft Visual C#.Net, C# Programming Language, .Net Editors & IDEs

Tags: C#, Webservice

Hi,

I am trying to Dynamically invoke a web service. The code was originally in Java and we are migratiing to .NET.

To invoke a webservice, we usually generate web referece based on wsdl generated code and use it.

Instead, if i have to dynamically invoke a web service method, given that i know the following

- URL with ip
- Service name
- port
- namespace

This is available in java, sample code given below. I need to implement the same in c#. Any pointers will be a BIG BIG HELP for me .

Java has some 3rd party objects as shown in the code below.


//URL wsdl = new URL(url);
String tempServiceName = getServiceName(serviceName);
QName serviceQName = new QName(targetNameSpace, tempServiceName);
QName port = new QName(targetNameSpace, portName);
QName operation;
operation= new QName(targetNameSpace, reqInfo.getRequestMethod());

org.apache.axis.client.ServiceFactory factory = new ServiceFactory();
//org.apache.axis.client.Service service = (Service) factory.createService(new URL(url), serviceQName);
org.apache.axis.client.Service service = (Service) factory.createService(serviceQName);
org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall(port, operation);
call.setReturnType(XMLType.XSD_STRING);
call.addParameter("string", XMLType.XSD_STRING, ParameterMode.IN);

//-------------settign the header
org.apache.axis.message.PrefixedQName svcName = new org.apache.axis.message.PrefixedQName("http://schemas.xmlsoap.org/ws/2002/07/secext", "Security", "wsse");
org.apache.axis.message.SOAPHeaderElement sh = new org.apache.axis.message.SOAPHeaderElement(svcName);
javax.xml.soap.SOAPElement sub = sh.addChildElement("UsernameToken");
javax.xml.soap.SOAPElement element = sub.addChildElement("Username");
element.addTextNode(userName);
element = sub.addChildElement("Password");
element.addTextNode(password);
call.addHeader(sh);
//------------

// int iIndexWsdl = url.indexOf("?");
// String strEndPointAddress = url.substring(0, iIndexWsdl);
call.setTargetEndpointAddress(url);
// String requestXML= CommonHelper.getInstance().loadFile(reqInfo.getRequestXML().trim()).toString();
logger.info("request XML:"+reqInfo.getRequestXML());
//long startTime=logger.perf("calling webservice");
long startTime= System.currentTimeMillis();
String response = (String) call.invoke(new Object[]{reqInfo.getRequestXML().trim()});
// long endTime=logger.perf("timeTaken for webserviceCall:",startTime);
long endTime=System.currentTimeMillis();
Start Free Trial
 
 
[+][-]03.06.2008 at 01:47PM PST, ID: 21065130

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 01:49PM PST, ID: 21065143

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 01:49PM PST, ID: 21065147

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 02:35PM PST, ID: 21065491

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 03:44PM PST, ID: 21065950

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 03:02AM PDT, ID: 21149481

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.18.2008 at 07:53AM PDT, ID: 21151653

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language, .Net Editors & IDEs
Tags: C#, Webservice
Sign Up Now!
Solution Provided By: Jzzzz
Participating Experts: 2
Solution Grade: B
 
 
[+][-]03.18.2008 at 07:55AM PDT, ID: 21151686

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.19.2008 at 08:27PM PDT, ID: 21168051

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628