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!
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!
精彩评论