gpt4 book ai didi

c# - 带有附件/MIME 内容的 SOAP

转载 作者:行者123 更新时间:2023-11-30 18:05:37 28 4
gpt4 key购买 nike

需要从第三方发送和接收以下格式的 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 消息的一部分发送,这是我们第一次接触它。谢谢!

最佳答案

备注 ServiceStack您可以通过 multipart/form-data 内容类型接受上传的 HTTP 文件,这是获得最佳互操作性和性能的推荐方式。

GitHub's Rest Files project 中有一个这样做的例子 。以下是显示如何上传文件的 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));
}

您可以 view-source of the Ajax example了解如何在 JavaScript 中执行此操作。

下面是处理上传文件的网络服务实现:

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

希望对您有所帮助!

关于c# - 带有附件/MIME 内容的 SOAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5347100/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com