2011-03-18 85 views
2

需要在以下格式從第三方發送和接收SOAP消息:SOAP帶附件/ MIME內容

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(SOAP Frameworks for .NET)。

我們也看到了DIME和MTOM的提及。這可以代替SWA(帶附件的SOAP)消息嗎?

如果您需要更多信息,請讓我知道。我們主要致力於發送二進制數據作爲SOAP消息的一部分,這是我們第一次接觸到它。謝謝!

+1

您的第三方是時代背後的路。 swa和DIME都不是有效的標準。他們幾乎死了。 – 2011-03-18 01:32:58

回答

1

注意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中做到這一點。

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

希望它能幫助!

+0

我想補充說我使用SharpMIMETools庫來讀取附件。我推出了自己的即時解決方案。事實上,你提到「多部分」是什麼幫助了很多,因爲搜索「SOAP瓦特/附件」產生較少有用的信息。 – 2011-05-12 11:42:40