public void Call_AddInts() { var soap = @"<?xml version=""1.0"" encoding=""UTF-8""?> <s:Envelope xmlns:s=""http://www.w3.org/2003/05/soap-envelope"" xmlns:a=""http://www.w3.org/2005/08/addressing""> <s:Header> <a:Action s:mustUnderstand=""1"">AddInts</a:Action> <a:MessageID>urn:uuid:e6be43e0-c120-4ba8-920e-7ecaa1823fd2</a:MessageID> <a:ReplyTo> <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> </a:ReplyTo> <a:To s:mustUnderstand=""1"">http://localhost:50000/api/Soap12</a:To> </s:Header> <s:Body> <AddInts xmlns=""http://schemas.servicestack.net/types"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""> <A>1</A> <B>2</B> </AddInts> </s:Body> </s:Envelope>"; var responseXml = ServiceClientBaseUri.CombineWith("/soap12") .PostToUrl(soap, requestFilter: req => req.ContentType = "application/soap+xml; charset=utf-8"); responseXml.Print(); Assert.That(responseXml, Does.Contain("<Result>3</Result>")); }
public void Sending_invalid_request_returns_invalid_response() { var soap = @"<?xml version=""1.0"" encoding=""UTF-8""?> <s:Envelope xmlns:s=""http://www.w3.org/2003/05/soap-envelope"" xmlns:a=""http://www.w3.org/2005/08/addressing""> <s:Header> <a:Action s:mustUnderstand=""1"">AddInts</a:Action> <a:MessageID>urn:uuid:e6be43e0-c120-4ba8-920e-7ecaa1823fd2</a:MessageID> <a:ReplyTo> <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> </a:ReplyTo> <a:To s:mustUnderstand=""1"">http://localhost:50000/api/Soap12</a:To> </s:Header> <s:Body> <AddInts xmlns=""http://schemas.servicestack.net/types"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""> <A>not a</A> <B>number</B> </AddInts> </s:Body> </s:Envelope>"; var responseXml = ServiceClientBaseUri.CombineWith("/soap12") .PostToUrl(soap, requestFilter: req => req.ContentType = "application/soap+xml; charset=utf-8"); var doc = new XmlDocument(); doc.LoadXml(responseXml); var responseMsg = Message.CreateMessage(new XmlNodeReader(doc), int.MaxValue, MessageVersion.Soap12WSAddressingAugust2004); using (var reader = responseMsg.GetReaderAtBodyContents()) { var bodyXml = reader.ReadOuterXml(); var responseType = typeof(AddIntsResponse); var response = (AddIntsResponse)Serialization.DataContractSerializer.Instance.DeserializeFromString(bodyXml, responseType); Assert.That(response.ResponseStatus.ErrorCode, Is.EqualTo(nameof(SerializationException))); Assert.That(response.ResponseStatus.Message, Does.Contain("Error trying to deserialize requestType:")); } }
public void Does_return_Custom_SoapFault() { var responseSoap = ServiceClientBaseUri.CombineWith("/Soap12") .GetStringFromUrl(method: "POST", requestBody: @"<s:Envelope xmlns:s=""http://www.w3.org/2003/05/soap-envelope"" xmlns:a=""http://www.w3.org/2005/08/addressing""> <s:Header> <a:Action s:mustUnderstand=""1"">SoapFaultTest</a:Action> <a:MessageID>urn:uuid:84d9f946-d3c3-4252-84ff-0b306ce53386</a:MessageID> <a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address> </a:ReplyTo> <a:To s:mustUnderstand=""1"">http://localhost:20000/Soap12</a:To> </s:Header> <s:Body> <SoapFaultTest xmlns=""http://schemas.servicestack.net/types"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""/> </s:Body> </s:Envelope>", contentType: "application/soap+xml; charset=utf-8", responseFilter: res => { }); Assert.That(responseSoap, Is.EqualTo( @"<?xml version=""1.0"" encoding=""utf-8""?><s:Envelope xmlns:s=""http://www.w3.org/2003/05/soap-envelope""><s:Body><s:Fault><s:Code><s:Value>s:Receiver</s:Value></s:Code><s:Reason><s:Text xml:lang=""" + System.Globalization.CultureInfo.CurrentCulture.Name + @""">Test SOAP Fault</s:Text></s:Reason></s:Fault></s:Body></s:Envelope>")); }