如何在WCF中接收带附件的soap消息

时间:2013-09-02 16:11:37

标签: c# wcf web-services soap

我在c#中有一个web服务,我收到带有附件的肥皂消息。 这是一个请求的wireshark日志

POST /scripts/vivo_sdp/ReceiveMmsNotificationService.asmx HTTP/1.1 SOAPAction: ""Content-Type: multipart/related; type="text/xml"; start="<sgp@email.com>"; boundary="----=_Part_1012.1378126647" Host: 1.1.1.1:0000 Connection: closeContent-Length: 5078 ------=_Part_1012.1378126647Content-Type: text/xml; charset=UTF-8Content-Transfer-Encoding: 8bitContent-ID: <sgp@email.com>
<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <ns1:NotifySOAPHeader xmlns:ns1="http://www.huawei.com.cn/schema/common/v2_1">
            <ns1:spRevId>XXXXXXX</ns1:spRevId>
            <ns1:spRevpassword>XXXXXXXX</ns1:spRevpassword>
            <ns1:spId>000370</ns1:spId>
            <ns1:serviceId>0100218100</ns1:serviceId>
        </ns1:NotifySOAPHeader>
    </soapenv:Header>
    <soapenv:Body>
        <ns2:notifyMessageReception xmlns:ns2="http://www.csapi.org/schema/parlayx/multimedia_messaging/notification/v2_4/local">
            <ns2:correlator>01090212572613003106</ns2:correlator>
            <ns2:message>
                <messageIdentifier>hwiuFVMFHjTfK9</messageIdentifier>
                <messageServiceActivationNumber>XXXXXXX</messageServiceActivationNumber>
                <senderAddress>tel:XXXXXXXXXX</senderAddress>
                <priority>Default</priority>
                <dateTime>2013-09-02T09:50:58-03:00</dateTime>
            </ns2:message>
        </ns2:notifyMessageReception>
    </soapenv:Body>
</soapenv:Envelope>
------=_Part_1012.1378126647Content-ID: <oQpSk>Content-Location: 01smilContent-Transfer-Encoding: 8bitContent-Type: application/smil; name=01smil<smil><head><layout><root-layout width="240" height="320" /><region id="Image" width="100%" height="70%" left="0%" top="0%" fit="meet" /></layout></head><body><par dur="8000ms"><img src="Bunny.svgz" region="Image" /></par></body></smil>
------=_Part_1012.1378126647Content-ID: <Bunny.svgz>Content-Location: Bunny.svgzContent-Transfer-Encoding: 8bitContent-Type: application/oct-stream; name=Bunny.svgz...........Z.n.G.}v...,...3....!m QR` ....b....ea.J.(....9=$EzI..\..k..8....S.N.....?_7.&......@..4.....jzy8........~..._...j2....7.......I.....n^/5..5.6...Us...f6o.....^M.S/../............_|..i...q.....~{....l.....W.f.
..p......:....O.>h.o.........yp.fv9.jv~..j|7..!...!&.1.......k..Asuq88}.........p..j..T.!/.__M..m..R.........A.K...O^4.W.....................
...7.H..`B...G.....t........O......>..a./.n......lr7...T+\....
.....
n_..C.;W..A........b.IV..76.N.:....;.....]..\<.z1....BkM..m..u.sP2.{Lj.(..[.d.+.56I+..O...x1!.1F..V./...\..>..S.
.p..l06......Rqm0.eLe..G........7..Xp
,......|...+c.D.k..z.}j.`*ii.W....7.V.&%.8Z;...0J..`.[.t..q..S0%...}..........p..W.{..F..
.......p{:......yz7..c'.?.s..:`&...........z.=...."..B.......3./....~.[.C.b......x...8I.>..i..3....{r>..\\M..J!..W'?.O..rq.....\r....1......HA......A
..)......z8p../9...&..'....
?;......|8..|>.z.9.UBn./E..G....F.|j.
\
.|A..1..7.Ms.....$.....r
...n|s
...(.Q.......<....
......\.[.Kg.....%)[..............(y.c..........XN.7.'...]....[$...h..M.}H.....?[.........q....y.#.....uE..[....k.I..A..Pu.."..z'C<A.OS.."*]c.u.V.Rj7....k..}<.z..jR.y..sJO.D..$.e#$.h......34l.}'..G.Y..B.p.hD...W...<....#../
z......."e...N....v.s...~..3V&...^..h.p...m.O<.O....MI...'........... ......0..
NH.=.1.3...e.qL....T.<......Ya...r.o.0.o.&S..b)..`.P.J..24..x0z..6..-...N."....Qc..0...G....5.3.G.....6.C........f$e.G.\..e..4.7.J}F".q.8..^.P...&).:.]|u.".7..W.....spE).$.....$..0s^M..t..y....4"..{..-.v..H..I...{M....L.v......d.M..<.b.m`H.I.N..Y.5pfk..q#....6#..Y:.:.V.L.7...s....(...t.%..:.k.o\...@.E..............,.....?)........h....:.9>.HA.g..-}....o.|.2.H#L...(...\r"....=..C....Y......J.c...:`..Jf.+[0...H.U..q.
.].l.@X..k0..#.;.sU......1...#d.."m..4\...L.. .....5..=@.....i....)x.....W.yu........V.v....{.S?Fn{.c'..N%.I.v`Cl.......&:j]U...^ ..n*......V..)%w@..n.{4S.Q.8.*R.D.}.b.H@.@Y
.
....N...PxK........T}V..L.0...MQ`%H=.6H..j.HU..T.{.....b/......B........-=A(w). yE...O%?...t.......,.Y.!.......-..K....fG....
`...6.,.823..4.I.*..@...C.V2=.]\erW...W...!.
J..cT....@.m.2R......."J.f............}.M.qO,#...n.eFpq~..BA.W:...h.OA......>Ih.?..=.#...%Y.9`>..v.$j...3.......!8=>:>y>..
Z...7.b..@..".V..f\.C..7........D..*`y..vM..7f.......Pn.
..T.u..Cd...3.sp.>.g.=5...:..`b-..!h.....fr......K.....1.Fh+
}eLB(...X(+@N`..P....+P._o,..z4........Y.21+....e.g.{.Y.^l..Z..3,>.G...v...lf2.}....?...!vs..Y@....
T...x....
.......g[....X..'v.R...A.l.Q
.f.}x..l.T...`.....-.O.Q.............R..-.1K*..j..R.j...T[E..M..j.....L...P.%'670e.r.........Q..h3oe.,.......-.N......}..kg.....M#.....q)i.1...]&v.`..e.....]..#...1B..&(1..3..B.....j..T;.%..,....D...........L{..r?...5r"[D0Y=.._r.........Q..J.
...C...X{..l.z..c;......1G.Z.....\...u../y...?.....'.G._.U.N...y....)8.....%-.........).%...!....SE.vz.0;....=....I.Y.....Fv.=..HUL.....<B...v..... Y....+...i...p|L...Pa9...)@#..O...3K..q..S....p... hE..or.k...Vb.^8.".Td...N..g..U}...du........6>kSW...i..(.L.S.`.0..?1.7....e..tH`..>b.y..>...
....4..t...~W.t|....9.wNN...._......giE.....@.I. 0j..#v.....*^.&%.%L...+.........e....l...J"y
Q.2..]c.
.&..*$O....L.]A...;....k1..k+...E..._P....fc..R..v).oq.1....@I..i>.......P...Y`^....3....82..R_fY).'j..B.a?......M.......$R`......
.8...bF..*.y..`~..k@....*cc..M..i.......Z."W
.`!..L&.R"z...
`......).8.k...K&......0)P....R..."..B....d.W.,....:.....S...u...d<o...S..S.q3X.pz3.o<~.g..=....q.....".v%..
------=_Part_1012.1378126647--

这就是我的服务器给出的答案

HTTP/1.1 500 Internal Server ErrorConnection: closeDate: Mon, 02 Sep 2013 12:57:27 GMTServer: Microsoft-IIS/6.0P3P: CP="CAO PSA OUR"X-Powered-By: ASP.NETX-AspNet-Version: 2.0.50727Cache-Control: privateContent-Type: text/xml; charset=utf-8Content-Length: 754
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 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">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Server</faultcode>
            <faultstring>The root element for the request could not be determined. When RoutingStyle is set to RequestElement, SoapExtensions configured via an attribute on the method cannot modify the request stream before it is read. The extension must be configured via the SoapExtensionTypes element in web.config, or the request must arrive at the server as clear text. ---&gt; Data at the root level is invalid. Line 1, position 1.</faultstring>
            <detail />
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

这是方法的签名

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
[System.ComponentModel.ToolboxItem(false)]
public class ReceiveMmsNotificationService : WebService, IMessageNotificationBinding, IReceiveMessageBinding
{
    [WebMethod]
    public notifyMessageReceptionResponse notifyMessageReception(notifyMessageReception notifyMessageReception1)
    {
        notifyMessageReceptionResponse result = new notifyMessageReceptionResponse();
        return result;
    }
}

如何更改我的网络服务,以便我可以接受带附件的邮件?

1 个答案:

答案 0 :(得分:0)

这些是mime / swa类型的附件。默认情况下,wcf不支持它们(仅支持mtom),但您可以使用this extension