带有附件/MIME 内容的 SOAP

发布于 2024-10-23 20:07:03 字数 1091 浏览 6 评论 0原文

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

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 技术发送此类消息的支持非常少。

如果您有此类操作的起点,请告诉我。我们已经了解了 ServiceStack 和 PocketSOAP(.NET 的 SOAP 框架)。

我们还看到提到过 DIME 和 MTOM。这可以代替 SWA(带有附件的 SOAP)消息吗?

如果您需要更多信息,请告诉我。我们主要尝试将二进制数据作为 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-- 

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.

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).

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

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零時差 2024-10-30 20:07:03

请注意,在 ServiceStack 中,您可以通过 multipart/form-data 内容接受上传的 HTTP 文件-键入这是实现最佳互操作性和性能的推荐方式。

GitHub 的 Rest Files 项目 中有一个执行此操作的示例。
以下是显示如何上传文件的 C# 客户端示例:

[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));
}

您可以 查看 Ajax 示例的源代码,了解如何在 JavaScript 中执行此操作。

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

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();
}

希望它有帮助!

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.

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));
}

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

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文