SOAP与附件/ MIME内容 [英] SOAP with Attachment / MIME content

查看:501
本文介绍了SOAP与附件/ MIME内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要从第三方发送和接收SOAP消息的格式如下:

Need to send and receive a SOAP message in the following format from a third party:

POST /api HTTP/1.1 
Host: mytesthost.com
Content-Type: multipart/related;  
boundary="aMIMEBoundary";  
type="text/xml";  
start="<soap-start>" 
Content-Length: 2014 
SOAPAction: "" 

--aMIMEBoundary 
Content-Type: text/xml; charset=us-ascii 
Content-Transfer-Encoding: 7bit 
Content-ID: <soap-start> 

<?xml version="1.0" encoding="UTF-8"?> 
<soap-env:Envelope xmlns:soap-
env="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap-env:Header>
... 
</soap-env:Header> 
<soap-env:Body> 
...
</soap-env:Body> 
</soap-env:Envelope> 

--aMIMEBoundary 
Content-Type: image/gif 
Content-ID: dancingbaby.gif 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

<Binary Data Here> 

--aMIMEBoundary-- 

这被认为是SOAP与附件?我们刚刚开始寻找到这一点,并发现了非常薄的支持使用.NET技术发送此类邮件。

Is this considered "SOAP with Attachment"? We just started looking into this and found very thin support for sending this type of message using .NET technologies.

请让我知道,如果你有一个起点,这种类型的操作。我们已经看了ServiceStack和PocketSOAP(SOAP框架.NET)。

Please let me know if you have a starting point for this type of operation. We've looked at ServiceStack and PocketSOAP (SOAP Frameworks for .NET).

我们还看到了DIME和MTOM提及。可这需要一个SWA(SOAP附件)消息的地方?

We've also seen DIME and MTOM mentioned. Can this take the place of an SWA (SOAP with Attachment) message?

请让我知道如果你需要更多的信息。我们主要是想集中在发送二进制数据作为SOAP消息的一部分,这是我们第一次接触到它。谢谢!

Please let me know if you need more info. We're mainly trying to focus on sending binary data as part of a SOAP message and this is our first exposure to it. Thanks!

推荐答案

请注意在 ServiceStack 可以接受上传HTTP文件通过的multipart / form-data的的Content-Type这是建议的方法以获得最佳的互操作性和性能。

Note in ServiceStack you can accept uploaded HTTP Files via the multipart/form-data Content-Type which is the recommend way for optimal interoperability and performance.

有做这个的例子在 GitHub的休息文件项目 。 下面是展示如何上传文件C#的客户端的例子:

There's an example of doing this in the GitHub's Rest Files project. Here is the C# client example showing how to upload a file:

[Test]
public void Can_WebRequest_POST_upload_file_to_save_new_file_and_create_new_Directory()
{
    var restClient = CreateRestClient();

    var fileToUpload = new FileInfo(FilesRootDir + "TESTUPLOAD.txt");

    var response = restClient.PostFile<FilesResponse>("files/UploadedFiles/", 
        fileToUpload, MimeTypes.GetMimeType(fileToUpload.Name));

    Assert.That(Directory.Exists(FilesRootDir + "UploadedFiles"));
    Assert.That(File.ReadAllText(FilesRootDir + "UploadedFiles/TESTUPLOAD.txt"),
            Is.EqualTo(TestUploadFileContents));
}

您可以<一href="https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/RestFiles/RestFiles/default.htm"相对=nofollow>阿贾克斯例子查看源代码来看看如何做到这一点在JavaScript中。

You can view-source of the Ajax example to see how to do this in JavaScript.

这里是Web服务实现来处理上传的文件:

And here is the web service implementation to process the uploaded files:

public override object OnPost(Files request)
{
    var targetDir = GetPath(request);

    var isExistingFile = targetDir.Exists
        && (targetDir.Attributes & FileAttributes.Directory) != FileAttributes.Directory;

    if (isExistingFile)
        throw new NotSupportedException(
        "POST only supports uploading new files. Use PUT to replace contents of an existing file");

    if (!Directory.Exists(targetDir.FullName))
    {
        Directory.CreateDirectory(targetDir.FullName);
    }

    foreach (var uploadedFile in base.RequestContext.Files)
    {
        var newFilePath = Path.Combine(targetDir.FullName, uploadedFile.FileName);
        uploadedFile.SaveTo(newFilePath);
    }

    return new FilesResponse();
}

希望它能帮助!

Hope it helps!

这篇关于SOAP与附件/ MIME内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆