I have following XML Input for a WCF service. Using XmlReader I am validating the message and replaces with a new message. During this process the xml namespace alias is changed from xmlns:soapenv to xmlns:s
What change need to be done in the following C# code in order to maintain the namespace alias while recreating the message?
Refer WCF message body showing <s:Body>... stream ...</s:Body> after modification for viewing the correct replaced message content.
From WCF Extensibility – Message Inspectors
WCF Message objects can only be “consumed” once – and “consumed” can mean read, written or copied. The message body is essentially a read-once stream, so once it’s consumed it cannot be used again. So if, in the inspector code, one were to read the message, the WCF runtime wouldn’t be able to reuse that message in the rest of its pipeline (i.e., to encode it to send as a reply or to parse it into operation parameters). So if the inspector code needs to read the message, it’s the responsibility of the inspector to recreate the message.
Input
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header>
<To soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://local:54956/Service1.svc</To>
<Action soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/GetData</Action>
</soapenv:Header>
<soapenv:Body>
<tem:GetData>
<!--Optional:-->
<tem:value>4</tem:value>
</tem:GetData>
</soapenv:Body>
</soapenv:Envelope>
CODE
private void MyInspectorsValidateMessageBody(ref System.ServiceModel.Channels.Message message, bool isARequest)
{
string originalMessageText = message.ToString();
if (!message.IsFault)
{
XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
XmlReader bodyReader = message.GetReaderAtBodyContents().ReadSubtree();
//Settings
XmlReaderSettings wrapperSettings = new XmlReaderSettings();
wrapperSettings.CloseInput = true;
wrapperSettings.ValidationFlags = XmlSchemaValidationFlags.None;
wrapperSettings.ValidationType = ValidationType.Schema;
//Add a event handler for ValidationEventHandler of XmlReaderSettings
//Validation happens while read of xml instance
//wrapperSettings.ValidationEventHandler += new ValidationEventHandler(MyHandlerForXMLInspectionErrors);
XmlReader wrappedReader = XmlReader.Create(bodyReader, wrapperSettings);
this.isRequest = isARequest;
MemoryStream memStream = new MemoryStream();
XmlDictionaryWriter xdw = XmlDictionaryWriter.CreateBinaryWriter(memStream);
xdw.WriteNode(wrappedReader, false);
xdw.Flush(); memStream.Position = 0;
XmlDictionaryReader xdr = XmlDictionaryReader.CreateBinaryReader(memStream, quotas);
//Reconstruct the message with the validated body
Message replacedMessage = Message.CreateMessage(message.Version, null, xdr);
replacedMessage.Headers.CopyHeadersFrom(message.Headers);
replacedMessage.Properties.CopyProperties(message.Properties);
message = replacedMessage;
string replacedMessageText = replacedMessage.ToString();
}
}
OUTPUT
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://local:54956/Service1.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/GetData</Action>
</s:Header>
<s:Body>... stream ...</s:Body>
</s:Envelope>
Nope, it's not changing the namespace. It's changing the prefix used to refer to the namespace, but in both cases the namespace itself is "http://schemas.xmlsoap.org/soap/envelope/".
From the original document:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
And from the output:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
Nothing should care what prefix is being used - it's the URI of the actual namespace which is important.
Related
I have Soap web service https://test-submit.health263.systems:8081/apacewebservices/AMF1_0?wsdl. This has a method called process. My question is how do I create soap client to send a request, that submits/Retrieves information from the server. The example XML for the request is shown below:
<?xml version="1.0" encoding="UTF-8"?>
<Member xmlns="urn:apace:member:format:1.0">
<Request>
<Transaction>
<VersionNumber>1.0</VersionNumber>
<Number>434252-342234-6765</Number>
<SystemIdentifier>SYSTEM999</SystemIdentifier>
<DestinationCode>APACE</DestinationCode>
<ClientCountryCode>ZA</ClientCountryCode>
<Timestamp TimeZone="Africa/Johannesburg">20160601123456</Timestamp>
<TestIndicator>Y</TestIndicator>
<User>ProviderX/Jane Doe</User>
</Transaction>
<MembershipLookup>
<Funder>AFunder</Funder>
<WithMembershipNumber>
<MembershipNumber>123456789</MembershipNumber>
</WithMembershipNumber>
</MembershipLookup>
</Request>
</Member>
The response message is structured as follows :
<?xml version="1.0" encoding="UTF-8"?>
<Member xmlns="urn:apace:member:format:1.0">
<Response>
<Transaction>
<VersionNumber>1.0</VersionNumber>
<Number>434252-342234-6765</Number>
<Status>S</Status>
<Timestamp TimeZone="Africa/Johannesburg">20160601123500</Timestamp>
</Transaction>
<Membership NumberOfBeneficiaryRecords="2">
<Funder>AFunder</Funder>
<MembershipNumber>123456789</MembershipNumber>
<Beneficiary SequenceNumber="1">
<DependentCode>00</DependentCode>
<Type>P</Type>
<Status>A</Status>
<BiometricEnrolmentStatus>Y</BiometricEnrolmentStatus>
</Beneficiary>
<Beneficiary SequenceNumber="2">
<DependentCode>01</DependentCode>
<Type>D</Type>
<Status>A</Status>
<BiometricEnrolmentStatus>Y</BiometricEnrolmentStatus>
</Beneficiary>
</Membership>
</Response>
</Member>
Please help I am really stuck, Haven't used SOAP services with C#, I have tried examples online but the structure does not follow my message structures are more complicated
The actual message structure is structured as follows:
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:apac="http://apace.systems/apacewebservices/"
xmlns:urn="urn:apace:member:format:1.1">
<soap:Header>
<apac:secureToken>Token66657752</apac:secureToken>
</soap:Header>
<soap:Body>
<apac:process>
<apac:request>
<Member
xmlns="urn:apace:member:format:1.1">
<Request>
<Transaction>
<VersionNumber>1.1</VersionNumber>
<Number>30074</Number>
<SystemIdentifier>LIFEHEALTH</SystemIdentifier>
<DestinationCode>HEALTH263</DestinationCode>
<ClientCountryCode>ZA</ClientCountryCode>
<Timestamp TimeZone="Africa/Johannesburg">20200705123456</Timestamp>
<TestIndicator>Y</TestIndicator>
<User>CIMSZW/Jane Doe</User>
</Transaction>
<MembershipLookup>
<IncludeDetail>Y</IncludeDetail>
<Funder>CIMSZWA</Funder>
<WithMembershipNumber>
<MembershipNumber>11117374</MembershipNumber>
<DependentCode>00</DependentCode>
</WithMembershipNumber>
</MembershipLookup>
</Request>
</Member>
</apac:request>
</apac:process>
</soap:Body>
</soap:Envelope>
Hw do I create the SOAP envelope and the Header part with the Security Key Token
You have two options
Add as service reference , it will genrate the
use Visual studio developer prompt and consume the service using a proxy class
svcutil.exe https://test-submit.health263.systems:8081/apacewebservices/AMF1_0?wsdl /t:code /n:*,SampleNamespace /o:C:\Service\sampleServiceProxy.cs /config:C:\Service\sampleService.config /ct:System.Collections.Generic.List`1
You can use a couple different system libraries to create an HttpWebRequest, create custom xml, and insert that xml into your request before you send it. (system.net, system.xml.linq, system.io)
I was able to hit your web service but got a 500 error. (Hopefully you see a log or that wasn't yours!)
Here's a simple class that can call a SOAP web service. It's almost the xml that you need but might need some tweaking. If you're having issues making custom xml this may be a possible solution.
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApp1
{
/// <summary>
/// Random class
/// </summary>
class Class1
{
/// <summary>
/// Function that calls a SOAP web service
/// </summary>
public void CallSOAP()
{
try
{
// Construct http post request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://test-submit.health263.systems:8081/apacewebservices/AMF1_0"));
request.Method = "POST";
request.ContentType = "application/xml";
request.Accept = "application/xml";
// Setting a namespace for your xml
// I'm not sure the timezone one is set up properly
XNamespace soap = "urn:apace:member:format:1.0";
XNamespace timezone = "TimeZone=\"Africa/Johannesburg\"";
// This constructs your xml using the LINQ library. I modeled after your demo, but needs tweaking as I get 500 error from server.
XElement requestXML =
new XElement(soap + "Member",
new XElement("Request",
new XElement("Transaction",
new XElement("VersionNumber", "1.0"),
new XElement("Number", "434252 - 342234 - 6765"),
new XElement("SystemIdentifier", "SYSTEM999"),
new XElement("DestinationCode", "APACE"),
new XElement("ClientCountryCode", "ZA"),
new XElement(timezone + "Timestamp", "20160601123456"),
new XElement("TestIndicator", "Y"),
new XElement("User", "ProviderX/Jane Doe")
),
new XElement("MembershipLookup",
new XElement("Funder", "AFunder"),
new XElement("WithMembershipNumber",
new XElement("MembershipNumber", 123456789)
)
)
)
);
// Convert the xml into a stream that we write to our request
byte[] bytes = Encoding.UTF8.GetBytes(requestXML.ToString());
request.ContentLength = bytes.Length;
using (Stream putStream = request.GetRequestStream())
{
putStream.Write(bytes, 0, bytes.Length);
}
// Execute the request and get an xml response "reader". You can read all xml at once or line by line
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
var streamData = reader.ReadToEnd();
}
}
catch (Exception ex)
{
// Write exception to console & wait for key press
Console.WriteLine(ex.Message + ex.StackTrace);
Console.ReadKey();
}
}
}
}
I have below XML input. I need to call API and pass this as input but values will change dynamically. How can I build this input structure?
<?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/">
<acc>test</acc>
<pass>abc</pass>
<xmlInvData>
<![CDATA[
<MyData>
<name>test</name>
<number>900</number>
</MyData>
]]>
</xmlInvData>
<username>test</username>
<password>123</password>
</Test>
</soap:Body>
</soap:Envelope>
I have MyData Class in C# which can be useful to setup name and number values.
But how can I form a complete structure and pass to Api call? soap:Envelop and soap body?
HttpClient httpClient = new HttpClient();
string requestUri = "https://testurl";
var byteArray = Encoding.ASCII.GetBytes("username:password");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
HttpResponseMessage response = await httpClient.PostAsync(requestUri, httpContent);
I need to understand how to form httpContent as above my input json.
Assuming you've built the data structure and serialized it to a string called xml:
var httpContent = new StringContent(xml, Encoding.UTF8, "application/xml");
I have some web service (wrote in Java) and I need create client for it in .NET. The WebService has WS-Security and need PasswordDigest.
First of all, I've tested it in SoapUI and it's works for:
POST http://192.168.100.101:8181/services/ws/SomeService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="someMethod"
Content-Length: 971
Host: 192.168.100.101:8181
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soap:Envelope xmlns:not="http://existing-domain.com/op/integration/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsse:Security 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">
<wsse:UsernameToken wsu:Id="UsernameToken-2C1E2DE2B61EBB94E115572099598331">
<wsse:Username>SOME_LOGIN</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">rcSb6Hd8btcI9g6JvO7dGdiTBTI=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">PCoVwJm9oEXtusx6gkMb7w==</wsse:Nonce>
<wsu:Created>2019-05-07T06:19:19.824Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<not:someMethod/>
</soap:Body>
</soap:Envelope>
In the next step I've prepared simple client in .NET and check with Wireshark what it sends:
POST /services/ws/SomeService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="someMethod"
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Host: 192.168.100.101:8181
Content-Length: 1124
Expect: 100-continue
Connection: Keep-Alive
<soap:Envelope xmlns:not="http://existing-domain.com/op/integration/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsse:Security 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">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-85707168-b5c6-47dc-93e9-45afa466fa2a" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Username>SOME_LOGIN</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">g112a9eHPR1hXD4UH+Lh3o8JV/o=</wsse:Password>
<wsse:Nonce>EiUbo2DbXMGhM26fT+ZkJQ==</wsse:Nonce>
<wsu:Created>2019-05-07T06:27:59Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<not:someMethod />
</soap:Body>
</soap:Envelope>
Unfortunatelly I allways got 500 status code and response:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
<soap:Subcode>
<soap:Value xmlns:ns1="http://ws.apache.org/wss4j">ns1:SecurityError</soap:Value>
</soap:Subcode>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">A security error was encountered when verifying the message</soap:Text>
</soap:Reason>
</soap:Fault>
</soap:Body>
</soap:Envelope>
I'm pretty sure it's appear because of authorization problem (I had same message in SoapUI if provided wrong credentials).
The section in my client is created with:
UsernameToken t = new UsernameToken("SOME_LOGIN", "SOME_PASSWORD", PasswordOption.SendHashed);
string usernameTokenSection = t.GetXml(new XmlDocument()).OuterXml.ToString();
There is a few articels how to create PasswordDigits (Base64( SHA1(password + nonce + created) )), Nonce (Base64(RandomString)) or Created date but I can't find what is wsu:Id="UsernameToken-2C1E2DE2B61EBB94E115572099598331" and how to create it. Above code where I get xml from UsernameToken returns complete section so I decided to use it, but I noticed that it append wsu:Id="SecurityToken-85707168-b5c6-47dc-93e9-45afa466fa2a" (instead of wsu:Id="UsernameToken-2C1E2DE2B61EBB94E115572099598331"). I can change the name and remove - characters but it's nothing changed and I still get 500 Internal Server Error with message "A security error was encountered when verifying the message".
So, my question is how to generate UsernameToken section with proper wsu:Id="UsernameToken-XXXXXXXXXXXXXXX"data? What is it - just random string or some hash created based on username and password?
Got it! I noticed that SOAP sent from .NET client doesn't have attribute EncodingType in Nonce node. After little modification in code:
UsernameToken t = new UsernameToken("SOME_LOGIN", "SOME_PASSWORD", PasswordOption.SendHashed);
string usernameTokenSection = t.GetXml(new XmlDocument()).OuterXml.ToString().Replace("<wsse:Nonce", "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\"");
Everything works!
Whole code for .NET client:
public static void Execute()
{
UsernameToken usernameTokenSection = new UsernameToken("SOME_LOGIN", "SOME_PASSWORD", PasswordOption.SendHashed);
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(#"<soap:Envelope xmlns:not=""http://existing-domain.com/op/integration/services"" xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"">" +
"<soap:Header>" +
#"<wsse:Security 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"">"+
usernameTokenSection.GetXml(new XmlDocument()).OuterXml.ToString().Replace("<wsse:Nonce", "<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\"") +
"</wsse:Security>" +
"</soap:Header>"+
"<soap:Body>"+
"<not:someMethod/>"+
"</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();
Console.WriteLine(soapResult);
}
}
}
public static HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(#"http://192.168.100.101:8181/services/ws/SomeService");
webRequest.Method = "POST";
webRequest.Headers.Add("Accept-Encoding:gzip,deflate");
webRequest.ContentType = "application/soap+xml;charset=UTF-8;action=\"someMethod\"";
//NOTE: below it's not necessary
//webRequest.Host = "192.168.100.101:8181";
//webRequest.KeepAlive = true;
//webRequest.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)";
return webRequest;
}
static void Main(string[] args)
{
try
{
Execute();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadLine();
}
}
PS. For using UsernameToken class you have to using Microsoft.Web.Services2 reference, you can add it by Nuget from here: Microsoft.Web.Services2
PPS. I know that there is simpler way by Add Service Reference... but it require additional classes and modifications for creating Security node in Header, so I decided to send raw xml and manipulate it directly.
This is my sample Code for Web service. I'm new to SOAP application if someone can spot any problem here it's much appreciated. This error only happened if mustUnderstand attribute ="1"
[WebService(Namespace = "http://www.xxxx.co.uk/Integration/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class ADNHeaderContact : System.Web.Services.WebService
{
public MyHeader myHeader;
[WebMethod]
[SoapHeader("myHeader")]
public string HelloWorld()
{
XmlDocument xmlSoapRequest = new XmlDocument();
using (Stream receiveStream = HttpContext.Current.Request.InputStream)
{
receiveStream.Position = 0;
using (StreamReader readStream =
new StreamReader(receiveStream, Encoding.UTF8))
{
xmlSoapRequest.Load(readStream);
}
}
using (XmlBreaker readxml = new XmlBreaker())
{
using (ReponseSaveApplications respose = new ReponseSaveApplications())
{
return ("Hello");
}
};
}
}
My Postman post request
<?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:Header>
<MyHeader soap:mustUnderstand="true" xmlns="http:www.xxxx.co.uk/Integration/">
<MyValue>string</MyValue>
</MyHeader>
</soap:Header
<soap:Body>
<HelloWorld xmlns="http://www.xxxx.co.uk/Integration/" />
</soap:Body>
</soap:Envelope>
My Postman post response
<?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:MustUnderstand</faultcode>
<faultstring>System.Web.Services.Protocols.SoapHeaderException: SOAP header MyHeader was not understood.
at System.Web.Services.Protocols.SoapHeaderHandling.SetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client)
at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
SoapHeader.MustUnderstand Property
When an XML Web service client adds a SOAP header to an XML Web
service method call with the MustUnderstand property set to true, the
XML Web service method must set the DidUnderstand property to true;
otherwise, a SoapHeaderException is thrown back to the XML Web service
client by ASP.NET.
Which is the easiest way to consume a WSDL SOAP/SSO using C# ?
This is a third party system and i get this response:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<RetornaEstadosPorMarcaResponse xmlns="http://WebService-MultiLogin-2013/">
<RetornaEstadosPorMarcaResult>
<EstadosMDL>
<ID>int</ID>
<Nome>string</Nome>
<Sigla>string</Sigla>
</EstadosMDL>
<EstadosMDL>
<ID>int</ID>
<Nome>string</Nome>
<Sigla>string</Sigla>
</EstadosMDL>
</RetornaEstadosPorMarcaResult>
</RetornaEstadosPorMarcaResponse>
</soap:Body>
</soap:Envelope>
And this is how i'm calling it:
public AdminMaster.RetornaEstadosPorMarca.Estados ssoEstados = new AdminMaster.RetornaEstadosPorMarca.Estados();
ssoEstados.RetornaEstadosPorMarca(Library.Configuracoes.ChaveSSO, Convert.ToInt16(Library.Configuracoes.Marca));
I have already tried to receive it as a string and format it to use as XML but it didn't work because of <soap:Body> and <soap:Envelope>, i get an error because i have the ':' on the name and i don't think that's the easiest way to do it.
So, how do i access the information from the response ? Is there another way ?
EDIT:
After several hours and tests i finally found the problem, "my" SOAP also gives me a class to create a object to receive the response, i only had to use it:
//Here i have the object with the methods
private Library.ssoEstados.Estados objEstadosSSO = new Library.ssoEstados.Estados();
//Here i have the object to receive the response
private Library.ssoEstados.EstadosMDL[] objEstadosMDL;
Than it was only a matter of read the values i wanted and send it to my own object.
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(inputXml);
XmlNamespaceManager namespaces = new XmlNamespaceManager(xDoc.NameTable);
namespaces.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
namespaces.AddNamespace("ns2", "http://tempuri.org/");
XmlNode accountNode = xDoc.SelectSingleNode("/soapenv:Envelope/soapenv:Body/ns2:RetornaEstadosPorMarcaResponse/RetornaEstadosPorMarcaResult", namespaces);
XmlNode xnlAccount = accountNode.ChildNodes[0];
if (xnlAccount != null)
{
XmlDocument xAccount = new XmlDocument();
xAccount.LoadXml(xnlAccount.InnerText);
}
inputXml is a string containing your response xml.