I have a wsdl that has a method to send data, instead of send it by this method I want to just get the soap string that would have been sent if I use the method.
If someone know if that possible or how to this, thanks for the helper,
I have a wsdl that has a method to send data, instead of send it by this method I want to just get the soap string that would have been sent if I use the method.
If someone know if that possible or how to this, thanks for the helper,
I obviously don't know what your architecture or infrastructure is like so the following might not be applicable, but it sounds like there might be a 'mix-up' with responsibilities. Instead of publishing the SOAP payload on a MQ it is better to publish only the data the consumer will need to do what it needs to do. E.g. you publish the SOAP envelope onto the queue, but what if there is another consumer also interested in this message? It might not want it in the SOAP format but in a JSON format, or it just wants to update a database table based on the data published. I would say rather push the 'raw' data and let the consumer decide what to do with it...
Anyway... A quick and dirty way to achieve this:
MessageInspector:
public class MessageInspector :
IClientMessageInspector
{
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var r = request.ToString(); // this will return the SOAP string...
return request;
}
public void AfterReceiveReply(ref Message reply, object correlationState)
{
//throw new NotImplementedException();
}
}
EndpointBehavior:
public class MessageInspectorBehavior :
IEndpointBehavior
{
public void Validate(ServiceEndpoint endpoint)
{
//throw new NotImplementedException();
}
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
//throw new NotImplementedException();
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
//throw new NotImplementedException();
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime
.MessageInspectors
.Add(new MessageInspector());
}
}
And then setting the behavior on the client:
class Program
{
static void Main(
string[] args
)
{
var ser = new ServiceReference1.Service1Client();
ser.Endpoint
.Behaviors
.Add(new MessageInspectorBehavior());
var f = ser.GetData(10);
Console.WriteLine(f);
Console.ReadKey();
}
}
the problem here is that the call is still made to the service... The alternative is to create the SOAP message manually
Maybe this will help: How to post SOAP Request from .NET?