Last post Jan 21, 2014 10:21 PM by Happy Chen - MSFT
Jan 16, 2014 12:03 PM|ibradleyallen|LINK
i have a c# app and need to send SOAP messages. right now i have used soapUI and have the structure that i used to add in the data, i set the endpoint and network credentials, send it, and it works.
in my c# app, i take that entire SOAP page and... am totally lost.
i tried taking that page of xml and assigning it to a string or string array, string s = @"<xml webpage 12345>/ "website this and that"\[$type this and that\">"; and of course the compiler gives dozens of errors.
ive heard of the WSDL where the SOAP page is somehow loaded there, i could put it on a localhost port if needed, and then i could add it as a service reference? and then instantiate a new variable and then add or modify members of the message and then send
i have been trying, but am somewhat unfamiliar with this, thanks for any ideas or suggestions!
Jan 17, 2014 03:09 AM|Happy Chen - MSFT|LINK
According to your description, i would suggest you try to use the workaround below:
Client use XMLHTTP to call Web service via SOAP:
function btn_click (a, b)
var xmlObj = new ActiveXObject("Msxml2.DOMDocument") ;
var sXml = "<?xml version=\"1.0\" ?>" ;
sXml += "<soap:Envelope "
sXml += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " ;
sXml += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " ;
sXml += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" ;
sXml += "<soap:Body>" ;
sXml += "<Add xmlns=\"http://tempuri.org/\">" ;
sXml = sXml + "<a>" + a.value + "</a>" ;
sXml = sXml + "<b>" + b.value + "</b>" ;
sXml += "</Add></soap:Body></soap:Envelope>"
// Try to parse the XML string into DOM object
//To see the validated XML string is well-formed
XmlRequest.innerText = xmlObj.xml ;
var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP") ;
xmlHTTP.Open ( "Post", "http://localhost/ASP.NET/MyWebService.asmx", false) ;
xmlHTTP.setRequestHeader("SOAPAction", "http://tempuri.org/Add") ;
xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8" ) ;
MyResult.innerText = xmlHTTP.responseText ;
var xmlResponse = xmlHTTP.responseXML ;
answer.innerText = xmlResponse.selectSingleNode("soap:Envelope/soap:Body/AddResponse/AddResult").text ;
<p>Please input a:<input id="a" name="a"></input></p>
<p>Please input b:<input id="b" name="b"></input></p>
<input type="button" id="btn" value="Enter"
<p>Answer is <span id="answer"></span></p>
Please fefer to the links below for details:
ASP.NET Web Service
How to create a SOAP request with the help of WSDL and receive SOAP response
If you need more assistance , please let me know.
Jan 17, 2014 07:26 PM|ibradleyallen|LINK
Hi Happy Chen,
Thanks so much for your answer. i have been trying this for many hours. i cannot make it work. is this something that can be created within a c# form?
i looked at the other examples, and tried using a web request, but did not see how to instantiate it.
i will try stringbuilder, entering the parts line by line and try to send it this way...
Jan 18, 2014 07:47 PM|ibradleyallen|LINK
i have tried to use a similar solution, i used XElement to build up the entire message line by line. this fails:
exception: Name cannot begin with the '<' character, hexadecimal value 0x3C.
I created the SOAP message that works from soapUI using stringbuilder, adding line by line. when it has the quote marks, i use the string literal @ sign and double quotes "" and it creates the single quote mark correctly. but it errors out saying name
cannot begin with the < character...
the message is soap wrapping an xml message. i was not able to create or instantiate any html object to copy your code into the c# form. if I ADD and html file to the project? there is nothing that will instantiate it, it is totally invisible to the
project. i worry this is a bug in visual studio. i had 1 html and 3 xml files added in, compiling at least 10 times. then the build would fail, i would click start and let it build/save, then it started to fail saying the xml format was wrong. i took
the file out of the project, right click, exclude from project. the other 2 files not even showing up in the solution window. i cleared the contents and it compiled and ran. the 3rd time then it complained saying the xml file needs ?
Im surprised that i cannot just create the array of the message that worked and send it from the POST command. im not sure why i cannot even send a pre formatted message.
thanks for any help, this is much harder than it should be
Jan 19, 2014 05:32 PM|ibradleyallen|LINK
ok what i have done now is change the entire project to be running in ASP.net since a c# form cannot interact with web calls, i will migrate the entire project into something that can.
but WOW asp.net is hard to use. trying to design the form? buttons and textboxes only stick to certain parts of the page, there is no reason or clue why they only stick on certain parts of the page, and they DO NOT move. how people can make web pages
out of this is a mystery so far. all the controls apparently have to sit in a line and cannot be moved and its hard to resize them.
in the other c# form? even instantiated variables, strings with string s ="123"; error saying value is null. either the project got corrupted or its a bug. i have to migrate anyway.
Jan 21, 2014 03:22 AM|Happy Chen - MSFT|LINK
Because Your issue is out of support range of XML and XmlDataSource Control, I suggest that you can consult your issue on
WCF, ASMX and other Web Services forum:
http://forums.asp.net/28.aspx/1?WCF+ASMX+and+other+Web+Services for better solution and support. Experts there will further research this issue and provide you better support.
please refer to the links below:
Sending and Receiving SOAP Request in C#
Sending SOAP Requests by Using Visual Studio .NET Client (C#)
Thank you for your understanding.
Jan 21, 2014 12:11 PM|ibradleyallen|LINK
Hi Happy Chen
I solved the problem, i was able to create the xml file but needed to manually add a reference to it by using the project options page. then i could instantiate it, i pasted the working soap page then read in the page and POST method and it worked perfectly.
but now i have an XML question i need help with, if you want me to start a new thread i can but its related to this, in the xml file i use this for a template, i read it in but there are 3 values that have to be changed. i have been trying to use xdocument
and xelement to no avail. i can get to the element but can only read it out. if i try to reverse the logic it errors out saying the left side of the argument has to be something... which means it does a read operation, i cannot swap it and have it write
even using the indexing that found it. i know it needs to have the index number of the element but havent made this work
i can say find namespace + "departmentID" and it finds it. but if i say write at location (namespace+"departmentID") it fails
since the code deals with ONLY ONE xml file this way, it is always the same, i could say at position 300 insert this text: "234343" well then if the length were wrong that might not work on the other elements that have to be changed, but why cant there
be a way to say at element "departmentID" insert text .... ? this is all i need it to do, how can this be done ?? thanks so much
Jan 21, 2014 10:21 PM|Happy Chen - MSFT|LINK
Thanks for your reply.
Since you have solved the problem of initial post , please mark it as a answer which helps you or your own reply.
if you has an new question, please start a new thread. Please explain what you are trying to do in detail on there ?
you'd better provide the any additional code or markup related to this issue?
It may be a bit easier to resolve if it can be easily reproduced.