WebService SOAP Encoding UTF-16 instead of UTF-8 - c#

Is it possible to force a WebService in C# .NET to use encoding UTF-16 instead of UTF-8?
I have created a simple WebService which receives a XML Document.
WebService.asmx
public class WebApplication1 : WebService
{
[WebMethod(Description = "Test")]
public string Test(XmlDocument xmlDocument)
{
return "Test";
}
}
Output
POST /WebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Test"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="http://tempuri.org/">
<xmlDocument>xml</xmlDocument>
</Test>
</soap:Body>
</soap:Envelope>
If I try an pass an XML Document that is UTF-16 encoded, I get the following error:
XML Content:
<?xml version="1.0" encoding="utf-16"?> <Affiliate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" leadinnumber="ABCDABCD" xmlns:xsd="http://www.w3.org/2001/XMLSchema" mediaid="30000">
<Details>
<Amount>5000</Amount>
<FirstName>Delivery</FirstName>
<Surname>Testing</Surname>
<Tel>02034056978</Tel>
<Email>adfsdfsdfsd#live.co.uk</Email>
</Details>
</Affiliate>
Post Response
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: There is no Unicode byte order mark. Cannot switch to Unicode. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.CheckEncoding(String newEncodingName) at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) at System.Xml.XmlTextReaderImpl.Read() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read() at System.Xml.XmlReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) --- End of inner exception stack trace ---</soap:Text>
</soap:Reason>
<soap:Detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
Any help would be much appreciated :-)

You have to configure your web service. Go to globalization section of Web.config and make UTF-16 instead of UTF-8. The requestEncoding and responseEncoding attributes of the globalization tag should be set to UTF-16.
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
must be converted to
<globalization requestEncoding="utf-16" responseEncoding="utf-16"/>
This change will allow the web service to accept request and send response in UTF-16.
EDIT
For setting the encoding manually through code you can use following code:
// Set the path of the config file.
string configPath = "";
Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
GlobalizationSection configSection = (GlobalizationSection)config.GetSection("system.web/globalization");
configSection.RequestEncoding = Encoding.Unicode;
configSection.ResponseEncoding = Encoding.Unicode;

Related

How to send request to a method of Web Service from Postman?

I have an ASMX service, which has the below method. I want to debug this method, so I have put a breakpoint on it. But I am not able to send a request to it successfully, It gives a 404 error.
[WebMethod]
public void RequestNotification()
{
I have tried these options so far.
Page screenshots for reference.
This is how I am calling from the C# code, and this is also not hitting the breakpoint on the method RequestNotification of service. and it's not giving any exceptions also in the C# code.
MyService myService= new MyService ();
myService.RequestNotification();
Update: I have tried as described in the below answer, I am still getting 404.
Please find below the request screenshot.
Using POST call from Postman with XML Body
Demo code.
I will show this Calculator SOAP service for Add operation.
POST URL
http://www.dneonline.com/calculator.asmx
In body with XML ray selection
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>100</intA>
<intB>200</intB>
</Add>
</soap:Body>
</soap:Envelope>
I got response this from service
<?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>
<AddResponse xmlns="http://tempuri.org/">
<AddResult>300</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope>
If you click code button from Postman, you can get the curl command too.
curl --location --request POST 'http://www.dneonline.com/calculator.asmx' \
--header 'Content-Type: text/xml; charset=utf-8' \
--header 'SOAPAction: http://tempuri.org/Add' \
--data-raw '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<intA>100</intA>
<intB>200</intB>
</Add>
</soap:Body>
</soap:Envelope>
'
#Bench Vue's answer has helped me in solving the issue. I am able to solve the issue with the below request.
Request and Response:

Stamps.com webservice Error - (500) Internal Server Error

I am getting the Error below when calling the Authenticate method of Stamps.com webservice.
The remote server returned an error: (500) Internal Server Error.
Here is the SOAP 1.1 definition of the request.
POST /swsim/SwsimV45.asmx HTTP/1.1
Host: swsim.testing.stamps.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://stamps.com/xml/namespace/2015/05/swsim/swsimv45/AuthenticateUser"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/05/swsim/swsimv45">
<Credentials>
<IntegrationID>guid</IntegrationID>
<Username>string</Username>
<Password>string</Password>
</Credentials>
</AuthenticateUser>
</soap:Body>
</soap:Envelope>
Here is my code calling the service.
private void button2_Click(object sender, EventArgs e)
{
CallStampsService();
}
private void CallStampsService()
{
HttpWebRequest request = CreateHTTPWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(#"<?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""
xmlns:tns=""http://stamps.com/xml/namespace/2015/05/swsim/swsimv45"">
<soap:Body>
<AuthenticateUser>
<Credentials>
<IntegrationID>my_integration_id</IntegrationID>
<Username>my_username</Username>
<Password>my_password</Password>
</Credentials>
</AuthenticateUser>
</soap:Body>
</soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
MessageBox.Show(soapResult);
}
}
}
public static HttpWebRequest CreateHTTPWebRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(#"https://swsim.testing.stamps.com/swsim/SwsimV45.asmx");
webRequest.Headers.Add(#"SOAPAction: " + #"http://stamps.com/xml/namespace/2015/05/swsim/swsimv45/AuthenticateUser");
webRequest.ContentType = "text/xml;charset=utf-8";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
}
I contacted Stamps.com and their support said they can't offer much assistance regarding the code, but indicated that the following error appears on their end.
<faultstring>Server did not recognize the value of HTTP Header SOAPAction: http://stamps.com/xml/namespace/2015/05/swsim/swsimv45.</faultstring>
So I inspected my Header object and got this.
{SOAPAction: http://stamps.com/xml/namespace/2015/05/swsim/swsimv45/AuthenticateUser
Content-Type: text/xml;charset=utf-8
Accept: text/xml
Host: swsim.testing.stamps.com
Content-Length: 580
Expect: 100-continue
Connection: Keep-Alive
}
The application fails at this line.
WebResponse response = request.GetResponse()
So I inspected the innerXML and got this.
<?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\"
xmlns:tns=\"http://stamps.com/xml/namespace/2015/05/swsim/swsimv45\">
<soap:Body>
<AuthenticateUser>
<Credentials>
<IntegrationID>my_integrationID</IntegrationID>
<Username>my_username</Username>
<Password>my_password</Password>
</Credentials>
</AuthenticateUser>
</soap:Body>
</soap:Envelope>
I do not know where I am going wrong.
I feel your pain. I've used the method below with success:
-- POST
https://swsim.stamps.com/swsim/swsimv42.asmx
-- HEADER
SOAPAction: http://stamps.com/xml/namespace/2015/01/swsim/swsimv42/AuthenticateUser
Content-type: text/xml
-- BODY
<?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>
<AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/01/swsim/swsimv42">
<Credentials>
<IntegrationID>XXXXXXX</IntegrationID>
<Username>XXXXXXX</Username>
<Password>XXXXXXX</Password>
</Credentials>
</AuthenticateUser>
</soap:Body>
</soap:Envelope>
Please note there are numerous versions of the stamps.com namespaces. Some work great, others are frustrating.
Yes, Stamps docs are VERY confusing. Especially, in their bunch of WSDL versions. But their support's answer was surprisingly informative. The http://stamps.com/xml/namespace/2015/05/swsim/swsimv45 xmls reference is in the wrong place. But they didn't tell you. And why.
xmls references a namespace, class, where stored a definition for the entity that referenced it.
For example,<AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/01/swsim/swsimv42"> tells that a definition of AuthenticateUser is in http://stamps.com/xml/namespace/2015/01/swsim/swsimv42 namespace. A non-global SOAP element (custom) located in a custom namespace. Everything is OK here.
Or <soap:Envelope ... mlns:tns=""http://stamps.com/xml/namespace/2015/05/swsim/swsimv45""> tells that soap element's description should be used from http://stamps.com/xml/namespace/2015/05/swsim/swsimv45 namespace. But the soap:Envelope element is global for SOAP. And a local namespace doesn't have a definition for it. That's why there was an error.
To fix the issue you need to reference that namespace in a proper place. Move it from <soap:Envelope ...> to <AuthenticateUser ...>. And your SOAP envelope will be OK.
P. S. Know, that the question is very old. But it wasn't answered and could help somebody who googled it.

How to receive a soap message with attachment in WCF

I have a webservice in c# and I'm receiving soap messages with attachments.
This is the wireshark log of one request
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--
and this is the answer that my server is giving
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. ---> Data at the root level is invalid. Line 1, position 1.</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
This is the signature of the method
[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;
}
}
How can i change my webservice so i can accept messages with attachments?
these are mime / swa type of attachments. wcf does not support them by default (only mtom is supported) but you can use this extension.

SOAP fault message

I have to send a SOAP fault message over HTTP to another web service if something goes wrong with a server, so I have this code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<Response status="1">
<Description>DESC</Description>
<Errors>
<Error>500</Error>
</Errors>
</Response>
</soapenv:Body>
</soapenv:Envelope>
Is this a properly formatted SOAP fault message?
Is this a properly formatted SOAP fault message?
No it isn't. It should look something like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>...</faultcode>
<faultstring>...</faultstring>
<detail>...</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The SOAP specification specifies what a fault is. Yours looks like an error result object of some sort which has some disadvantages as explained here for example.
Your WS framework should properly generate faults if you throw exceptions. If you are not using a framework but building the fault in some other way, then it must look like in my example above or it can't be called a SOAP fault.
Hey Bogdan I wrote this code and works like a charm!
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>500</faultcode>
<faultstring>SERVER ERROR</faultstring>
<detail>
<Response_status>1</Response_status>
<Description>DESCRIPTION</Description>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
But another question how to send a SOAP success message with a http code 200 an also I have to have some additional parameters in the message, this is a part of it
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</soap:Body>
</soap:Envelope>
So with this also I have to send code 200, how to write that can I write it like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>200</faultcode>
<faultstring>OK</faultstring>
<detail>
<Response_status>0</Response_status>
<Description>SUCCESS</Description>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

Adding a custom SOAP header using c#

I have created a proxy class in c# using Wsdl.exe from the WSDL structure.
I need to serialize the proxy class and send to an HttpWebRequest.
This is the code I used to serialize the class
using (System.IO.Stream soapStream = new System.IO.FileStream(#"C:\SoapFormat.xml", System.IO.FileMode.OpenOrCreate))
{
System.Xml.Serialization.SoapReflectionImporter soapRefImp = new System.Xml.Serialization.SoapReflectionImporter();
System.Xml.Serialization.XmlTypeMapping xmlTypeMapping = soapRefImp.ImportTypeMapping(typeof(clsPerson));
System.Xml.Serialization.XmlSerializer xmlSerializer =
new System.Xml.Serialization.XmlSerializer(xmlTypeMapping);
xmlSerializer.Serialize(soapStream, p);
}
I am getting the xml as
<?xml version="1.0"?>
<clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1">
<FirstName xsi:type="xsd:string">Jeff</FirstName>
<MI xsi:type="xsd:string">A</MI>
<LastName xsi:type="xsd:string">Price</LastName>
</clsPerson>
I need to add soap envelope. how can i add in c#.
My output should be like this
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<clsPerson xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1">
<FirstName xsi:type="xsd:string">Jeff</FirstName>
<MI xsi:type="xsd:string">A</MI>
<LastName xsi:type="xsd:string">Price</LastName>
</clsPerson>
</soapenv:Body>
</soapenv:Envelope>
Do u need to create a string builder and add the soap envelope as string.
then insert the xml into that string.
for eg
string s= "<body>"+ xml + "</body">
Any other option in c# to create soap envelope?
I need to send this soapenvelope to a webservice as httprequest.
Any helps appreciated.
this requires webservice not wcf.
thanks
supriya

Categories

Resources