Using SOAP with .NET

S

Simon Kennedy

Hi All,

Is it possible to support SOAP methods determined at runtime?
I thought that by implementing a class derived from 'SoapReceiver' and
registering the class within the web.config file of our ASP.NET project
might do the job but this seems to only support one way communication.
I can receive the soap call and its arguments but I'm unable to determine
how to return the result. All documentation points towards using 'SoapService'
and the 'SoapMethod' attribute but this requires knowledge of the SOAP action/method
at compile time, which we don't have. I have tried the following code but without success:

public class CustomSoapReceiver
: SoapReceiver
{
protected override void Receive(SoapEnvelope message)
{
if (message.Context.Addressing.Action == "Add")
{
// extract x and y values from incoming SOAP
// message
double x = XmlConvert.ToDouble(
message.SelectSingleNode("//x").InnerText);
double y = XmlConvert.ToDouble(
message.SelectSingleNode("//y").InnerText);
double result = x+y;

// do something with result
// send response message to original sender
SoapEnvelope replyMessage = new SoapEnvelope();
replyMessage.Context.Addressing.Action = message.Context.Addressing.Action;
replyMessage.CreateBody();
replyMessage.Body.InnerXml = String.Format("<{0}Response><result>{1}</result></{0}Response>",
message.Body.SelectSingleNode("*").LocalName, result);

// create SoapSender for the reply address and send message
Microsoft.Web.Services2.Addressing.EndpointReference endPoint = ((Microsoft.Web.Services2.Messaging.SoapHttpRequestChannel)message.Context.Channel).RemoteEndpoint;
SoapSender responseSender = new SoapSender(endPoint);
responseSender.Send(replyMessage);
}
}
}

The 'Receive' method is suppose to take the x,y values, add them and return the result.
However the reply never seems to get back to the SOAP client. Is there a way to achieve my aim.

We are using 'VS.NET 2003' with the latest WSE2.

Thanks,

Simon. K
 
D

Dan Bass

Are you aware of Web Service support in .Net? This basically creates a "SOAP
server" for you and all that's needed is to create the methods in your
project language.

All the SOAP development is covered over so you needn't worry about it.

Dan.
 
S

Simon Kennedy

I'm aware of the Web Service support but I'm not sure how it can
be used to support methods/actions that I will not know about until
runtime. I know its easy to define a Web Service if you already know
what the interface/contract of the application is but if its user defined
(that is user based macros loaded at runtime) how do you do that?

Simon. K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top