cs0103 the name'debuggerDisplayProxy' does not exist in the current context - c#

I'm trying to construct a soap envelope to send data and, when I instantiate XmlDocument object, I'm getting this error "cs0103 the name'debuggerDisplayProxy' does not exist in the current context". I don't know what it is or how to solve it. I searched on the web and didn't find anything useful. Could you help, please?
Below, is the code where I try to do the envelope:
private static System.Xml.XmlDocument CreateSoapEnvelope(string xml)
{
var soapEnvelope = new System.Xml.XmlDocument();
soapEnvelope.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"">
<soap:Body>
<HelloWorld3 xmlns=""
http://localhost:52700/api/SOAPService/PostObject"">"
+ xml +
"</HelloWorld3></soap:Body></soap:Envelope>");
return soapEnvelope;
}
Below, the error:

Related

How to read an existing SOAP XML message?

I am trying to read a SOAP message such as the following one:
https://raw.githubusercontent.com/mrjeffstevenson3/mmimproc/master/data/testdata/examcard/PHANTOM_QT1_SLU_20151230.ExamCard
This is an XML file which starts with:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:ExamCard id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Philips.PmsMR.ExamCards.ECModel/philips.pmsmr.examcards.ecmodel_cs">
How am I supposed to read such file ? How can I write the code for rootClass ? Pseudo code:
var mySerializer = new XmlSerializer(typeof(rootClass));
using var myFileStream = new FileStream("PHANTOM_QT1_SLU_20151230.ExamCard", FileMode.Open);
var myObject = (rootClass)mySerializer.Deserialize(myFileStream);

Sending XML Web Request

We are currently working on a connection to a Web API via XML requests. Our XML statement is as far as correct and also the URL is correct. Nevertheless we receive the following error from the server:
The remote server has returned an error: (403) Inadmissible.
Is there at least one way to get a more detailed error message?
By the way, the API is not from us so we don't have access to the logs of the backend.
XML Request:
<?xml version="1.0" encoding="utf-8"?>
<OTA_PingRQ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="3.3" TimeStamp="2020-12-09T13:53:57" PrimaryLangID="en" Target="Production">
<EchoData><![CDATA[Hello World]]></EchoData>
</OTA_PingRQ>
Web Call:
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["otaRQ"] = xml;
var response =
wb.UploadValues("http://backend.cultuzz.com:7380/cultswitch/processOTA",
"POST", data);
string responseInString = Encoding.UTF8.GetString(response);
MessageBox.Show(responseInString);
}
If I use the ping example as documented here it works. Change your xml to this:
string xml = #"<OTA_PingRQ xmlns=""http://www.opentravel.org/OTA/2003/05""
Version=""3.30"" TimeStamp=""2011-07-24T10:07:24"" Target=""Production"">
<EchoData><![CDATA[Hello World!!]]></EchoData> </OTA_PingRQ>";
response:
<?xml version="1.0" encoding="UTF-8"?>
<OTA_PingRS PrimaryLangID="en" Target="Production"
TimeStamp="2020-12-09T13:46:19" Version="3.00" xmlns="http://www.opentravel.org/OTA/2003/05">
<Success/>
<EchoData><![CDATA[Hello World!!]]></EchoData>
</OTA_PingRS>

Consume Web Service with soap:mustUnderstand attribute

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.

Consume SOAP/SSO using C#

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.

XmlDocument CreateElement without xmlns under a prefixed element

I'm trying to compose a SOAP request to ebay FindingAPI web service by using C# XmlDocument class in the following code:
XmlDocument doc = new XmlDocument();
XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("soap", "Envelope", "http://www.w3.org/2003/05/soap-envelope"));
root.SetAttribute("xmlns", "http://www.ebay.com/marketplace/search/v1/services");
XmlElement header = (XmlElement)root.AppendChild(doc.CreateElement("soap", "Header", "http://www.w3.org/2003/05/soap-envelope"));
XmlElement body = (XmlElement)root.AppendChild(doc.CreateElement("soap", "Body", "http://www.w3.org/2003/05/soap-envelope"));
XmlElement request = (XmlElement)body.AppendChild(doc.CreateElement("findItemsByKeywordsRequest"));
XmlElement param = (XmlElement)request.AppendChild(doc.CreateElement("keywords"));
param.InnerText = "harry potter phoenix";
And, the XML output of above code is:
<soap:Envelope xmlns="http://www.ebay.com/marketplace/search/v1/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body>
<findItemsByKeywordsRequest xmlns="">
<keywords>harry potter phoenix</keywords>
</findItemsByKeywordsRequest>
</soap:Body>
</soap:Envelope>
However, this XML can't be recognized by the server because of the extra xmlns="" attribute in the findItemsByKeywordsRequest element. The desired XML output should be as below:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns="http://www.ebay.com/marketplace/search/v1/services">
<soap:Header/>
<soap:Body>
<findItemsByKeywordsRequest>
<keywords>harry potter phoenix</keywords>
</findItemsByKeywordsRequest>
</soap:Body>
</soap:Envelope>
Does anyone know what is the problem of my code and please give me some hints. Thanks!
Because your document has default namespace declared in the most outer element you have to repeat that namespace on every child element to avoid adding additional empty one.
Change request and param elements declaration to contain "http://www.ebay.com/marketplace/search/v1/services" namespace
XmlElement request = (XmlElement)body.AppendChild(doc.CreateElement("findItemsByKeywordsRequest", "http://www.ebay.com/marketplace/search/v1/services"));
XmlElement param = (XmlElement)request.AppendChild(doc.CreateElement("keywords", "http://www.ebay.com/marketplace/search/v1/services"));
With these changes your code produces following XML:
<soap:Envelope xmlns="http://www.ebay.com/marketplace/search/v1/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body>
<findItemsByKeywordsRequest>
<keywords>harry potter phoenix</keywords>
</findItemsByKeywordsRequest>
</soap:Body>
</soap:Envelope>

Categories

Resources