Creating MTOM attachment from small text file
- From: yewen <yewen@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 6 Mar 2007 14:56:10 -0800
I'm writing a .NET 2.0/WSE 3.0 client to Apache Axis2 v.1. web service server.
(the server may not be relevant to the problem I'm having) here.
I found a problem which MTOM attachment support of .NET 2.0/WSE 3.0. If the
attachment is a text file and the size of the attachment file is small than
769 bytes. My WSE 3.0 proxy will send out a SOAP message like the following.
POST /CMBSpecificWebService/services/CMWebService HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client
Protocol 2.0.50727.42)
SOAPAction: "urn:CreateItem"
Host: tangyew:9080
Content-Type: multipart/related; type="application/xop+xml";
boundary=--MIMEBoundary633083467731373248;
start="<0.633083467731373248@xxxxxxxxxxx>"; start-info="text/xml;
charset=utf-8"
Content-Length: 2365
Expect: 100-continue
----MIMEBoundary633083467731373248
content-id: <0.633083467731373248@xxxxxxxxxxx>
content-type: application/xop+xml; charset=utf-8; type="text/xml;
charset=utf-8"
content-transfer-encoding: binary
<soap:Envelope xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><soap:Header><wsa:Action>urn:CreateItem</wsa:Action><wsa:MessageID>urn:uuid:d5c14ca2-d81c-4cef-ac89-7872a2a70164</wsa:MessageID><wsa:ReplyTo><wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address></wsa:ReplyTo><wsa:To>http://tangyew:9080/CMBSpecificWebService/services/CMWebService</wsa:To><wsse:Security><wsu:Time
stamp
wsu:Id="Timestamp-31d829d7-f415-4402-a406-8f382bcc26de"><wsu:Created>2007-03-01T19:52:53Z</wsu:Created><wsu:Expires>2007-03-01T19:57:53Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><CreateItemRequest
xmlns="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema"><AuthenticationData><ServerDef><ServerName>marble</ServerName></ServerDef><LoginData><UserID>icmadmin</UserID><Password>password</Password></Login
Data></AuthenticationData><Item><ItemXML><XYZ_InsPolicy
XYZ_PolicyNum="57904965371" XYZ_Street="10555 OLIVE ST" XYZ_State="CA"
XYZ_City="Temple City" XYZ_ZIPCode="91780"><XYZ_Insured
XYZ_InsrdFName="Edward" XYZ_InsrdLName="Smith" /><XYZ_Insured
XYZ_InsrdFName="Jennifer" XYZ_InsrdLName="Smith" /><XYZ_VIN
XYZ_VIN="ICLA44P5KL9876543" /><ICMBASE><resourceObject MIMEType="text/plain"
xmlns="http://www.ibm.com/xmlns/db2/cm/api/1.0/schema"><label
name="policyForm"
/></resourceObject></ICMBASE></XYZ_InsPolicy></ItemXML></Item><mtomRef
ID="policyForm"
MimeType="text/plain">NDFjIGU3NCBXaW5NYWluCjQxYyBlNzQgICAgbHBDbWRMaW5lOiAnL1JFR1NFUlZFUicKNDFjIGU3NCBSdW4KNDFjIGU3NCAgICBscENtZExpbmU6ICcvUkVHU0VSVkVSJwo0MWMgZTc0ICAgIG5DbWRTaG93OiAxMAo0MWMgZTc0IGxlYXZpbmcgV2luTWFpbgpmYWtsZmprO2xhZmRzYWYNCmprZmxhbGtmYXMNCg==</mtomRef></CreateItemRequest></soap:Body></soap:Envelope>
----MIMEBoundary633083467731373248--
The actual attachment is encoded and insert as the content of <mtomRef>
element.
Web services server can not recognize the format of SOAP message. If the file
size is larger than 769 bytes, the attachment will be packaged into a
separate part
of the multi-part HTTP message, which web services server can handle.
The piece of code creating the attachment is
/// <summary>
/// Sets up an array of MTOMAttachments. The MTOMAttachments are
used to send the content of the documents parts to the server in the soap
message
/// </summary>
/// <param name="resources">array containing information regarding
the document part to be associated with the policy.</param>
/// <returns>new array of MTOMAttachments.</returns>
MTOMAttachment[] setupAttachments(string[,])
{
// Create MTOMAttachment objects for all the resources passed in
// the resources array provides the information for the document
parts to be sent to the server
MTOMAttachment[] attachments = new
MTOMAttachment[resources.GetLength(0)];
for (int i=0;i<resources.GetLength(0);i++)
{
attachments[i] = new MTOMAttachment();
attachments[i].ID = "policy1";
attachments[i].MimeType = "text/plain";
attachments[i].Value = File.ReadAllBytes("policy.txt");
}
return attachments;
}
MTOMAttachment proxy class generated from WSDL is
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema")]
public partial class MTOMAttachment {
private string idField;
private string mimeTypeField;
private byte[] valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ID {
get {
return this.idField;
}
set {
this.idField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string MimeType {
get {
return this.mimeTypeField;
}
set {
this.mimeTypeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute(DataType="base64Binary")]
public byte[] Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
Does anyone know if it's a bug/limitation of .NET/WSE SDK or if the way I'm
adding
MTOM attachment is not right? Any suggestion is appreciate.
.
- Prev by Date: Not able to configure web service to use WSE 3.0
- Next by Date: Re: Not able to configure web service to use WSE 3.0
- Previous by thread: Not able to configure web service to use WSE 3.0
- Next by thread: Re: WSE 3.O Web Service with ASP.Net Client using VB.Net
- Index(es):
Relevant Pages
|