WSE helps developers build scalable, secure Web services that cross security domains. It also supports sending SOAP messages using transports other than HTTP. Another feature is the ability to build a SOAP router, so SOAP messages could be sent to a SOAP router and the router will delegate the work to the applicable Web server hosting the Web service.
Yet another feature, and the subject of this article, is the support for Direct Internet Message Encapsulation (DIME). This is an important protocol for sending binary attachments, as it specifies a method for sending attachments in their binary form rather than encoding with either hexidecimal or base64 encoding, which can increase the size of the attachment by approximately 30 percent. In this article, I'll create the C# code necessary to attach a simple DIME attachment to a SOAP message.
If you haven't already installed the WSE 2.0, you'll need to download it from Microsoft's Web site. (Be sure you meet the requirements specified on the WSE 2.0 Web page.) Once you install it, you can begin creating your DIME service.
The first thing to do is to create an ASP.NET Web service project in Microsoft Visual Studio .NET (VS.NET). Add a reference to the Microsoft.Web.Services2 class library in your project. Then, add the following elements to the Web.config file within the <system.web> element:
<webServices>
<soapExtensionTypes>
<add type="Microsoft.Web.Services2.WebServicesExtension,
Microsoft.Web.Services2,Version=2.0.0.0,Culture=neutral,
PublicKeyToken=31bf3856ad364e35" priority="1" group="0" />
</soapExtensionTypes>
</webServices>
Another way you can accomplish this is to right-mouse click on the Project in the project view and choose WSE Settings 2.0... Select both check boxes on the General tab; this will add the appropriate config settings.
Finally, create the method that will attach the DIME attachment to the SOAP message. I'm going to add a method called CreateDimeAttachment(). This method will accept one input parameter, the absolute path to the file to attach:
public void CreateDimeAttachment(string filepath)
{
SoapContext ctx = ResponseSoapContext.Current;
DimeAttachment attach = new DimeAttachment("image/jpeg",
TypeFormat.MediaType,
filepath);
ctx.Attachments.Add(attach);
}
What happens here is the current context of the Web service response is stored to the local variable ctx. A new DimeAttachment is created using the image/bmp type format and the path to the file (I'm assuming that the path to the file is going to be a bitmap file). The new DimeAttachment is added to the Attachments collection of the current response context.
Now all you have to do is add the appropriate using statements to the top of the .asmx file:
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2;
using System.Net;
Here's my total example code for this solution:
In order to test your code, you must create a SOAP client. Simply using the supplied default page for invocation of the Web service will not work. You can create a SOAP client by creating a new ASP.NET Web application and adding a Web reference to your new Web service. You must also add the WSE configuration settings as above.








1
moises - 17/02/08
hola como estas
de donde eres
» Report offensive content