WSE allows you to send and receive messages using the TCP protocol with or without using a http server.

WSE provides the SoapSender and SoapReceiver classes to enable one way communication while the SoapClient and SoapService classes support bidirectional messaging.

To use the SoapSender class to send a message to a Soap Receiver you must create an end point reference pointing to where you want to send the message. An example from msdn for creating an end point reference is below:

Once you have the endpoint, you need to create an Envelope Message that holds the actual Message you want to send. Once you have configured the message you need to call the send method of the SoapSender instance to send the message to the end point. An example from msdn for doing this is below:

To receive the message on the other side you must create a class that inherits from SoapReceiver class. In the class override the Receive method to get the message from the sender. An example from msdn is below:

To actually get this to work though, you must register an instance of the receiver. This is done differently depending on if you are using tcp with a console application/windows service or hosting it in IIS using http. To register the receiver using tcp, you must create an endpoint for the receiver and register the endpoint with the instance of your custom receiver class. An example of this is below:

To configure the receiver with http, you must make sure the web config has a reference to WSE 3.0 in the config sections and then add an http handler of the type of you receiver in the web config. An example of this section from msdn is below:

For bidirectional communication you will need to create a class that inherits from SoapClient to server as the client. The constructor of this class should accept an endpoint reference as a parameter, passing it to the base constructor. Then in the class you must define methods to correspond to methods defined in a SoapService class (described later). The methods should be decorated with a SoapMethod Attribute. Each method should accept a SoapEnvelope and pass the envelope with the method name to the base SendRequestResponse method. An example of an implementation from msdn is below:

Then in the code that will be send the request you need to create an instance of your SoapClient passing in the end point reference. Then you can call the methods that you exposed passing in an envelope to be passed to the end point. An example from msdn is below:

// The destination variable is the EndpointReference // for the Web service.CustomSoapClient client = new TcpClient(destination); SoapEnvelope envelope = new SoapEnvelope();envelope.Context.Addressing.Action = new Action("soap.tcp://SomeNamespaceURI/myReceiver");envelope.SetBodyObject("Some message goes here"); // The envelope that is returned is the response data.SoapEnvelope returnEnvelope = client.RequestResponseMethod(envelope);

To receive the messages on the other side you must create a class that inherits from SoapService class. In the class you must define the methods that the client can invoke and decorate them with a SoapMethod Attribute. An example from msdn is below:

To actually get this to work though, you must register an instance of the service. This is done differently depending on if you are using tcp with a console application/windows service or hosting it in IIS using http. To register the receiver using tcp, you must create an endpoint for the service and register the endpoint with the instance of your custom service class. An example of this is below:

To configure the receiver with http, you must make sure the web config has a reference to WSE 3.0 in the config sections and then add an http handler of the type of you receiver in the web config. An example of this section from msdn is below:

WSE 2.0 used DIME Attachments for attaching large pieces of data to a Soap Message. WSE 3.0 uses Message Transmission Optimization Mechanism or MTOM to attach large pieces of data to a Soap Message.

To use MTOM you must add a MTOM element to the web config either manually or through the WSE Settings Wizard on the messaging tab. You must configure the client mode to on, and the server mode to optional or always depending on your requirements.

Once your application is configured to use MTOM, you can simply configure your web service methods to either return a byte array or accept a byte array as a parameter. Here is an example from msdn that returns a file to the client:

To send and receive from the client side you must add a MTOM element to the web config either manually or through the WSE Settings Wizard on the messaging tab. You must configure the client mode to on.

If you need to increase the maximum size of the attachment or timeout properties you must add or modify the httpRunTime node of the applications config file. An example of setting these values from msdn is below:

Then all you need to do is use the generated proxy for the client as normal. The following example from msdn demonstrates calling a service the returns a byte array which is converted into an image:

String fileName = "Winter.jpg";// Create an instance of the Web service proxy class.BinaryDataMTOMServiceWse serviceproxy = new BinaryDataMTOMServiceWse(); // Specify that MTOM encoding must be used.serviceproxy.RequireMtom = true; serviceproxy.SetPolicy("ClientPolicy");// Communicate with the Web service to get the requested file.byte[] response = serviceproxy.GetFile(fileName); MemoryStream memory = new MemoryStream(response); // Display the file in a picture box.pictureBox1.Image = System.Drawing.Image.FromStream(memory);