Answered by:
Posting data to an ASMX webservice

Question
-
User-1458727574 posted
I'm writing a small windows forms application that is posting data to a web service. Data can be passed either as a string or as an XML object. When I look at the ASMX page to get the list of supported operations I get the URL for the WSDL and a list of operations. The one I am interested in is listed. When I click on it I get examples of SOAP 1.1 and 1.2. For SOAP 1.2 I see the request/response as below:
POST /WEBSERVICES/DATASERVICE/DATASERVICE2.ASMX HTTP/1.1 Host: xxxxxxxxxxxxxxxxxxxx Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <XML_IMPORT xmlns="DataService"> <IMPORT>xml</IMPORT> </XML_IMPORT> </soap12:Body> </soap12:Envelope>
HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <XML_IMPORTResponse xmlns="DataService"> <XML_IMPORTResult>xml</XML_IMPORTResult> </XML_IMPORTResponse> </soap12:Body> </soap12:Envelope>
I'm using C# in VS2017. I've created an empty Windows forms app. I have been provided with an XSD for the data structure of the XML I need to send. I have create a class from that in VS. I have added a service reference and given it the URL of the WSDL. I pressed Go and it loads the WSDL and shows me the available services. They are:
- DataService2HttpGet
- DataService2HttpPost
- DataService2Soap
So, assuming I have created the object, how do I go about sending that object to the end point and pick the response up?
Monday, June 17, 2019 11:52 AM
Answers
-
User475983607 posted
So, assuming I have created the object, how do I go about sending that object to the end point and pick the response up?Creating a service reference generates all the "proxy" code you need to call the service in an object oriented manor. Then remote method arguments are usually just object that you fill. Intellisense should guide you. The same goes for the response, it will be an object in the generated file.
Creating a service reference is supposed to make calling a service end point just like calling a method.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 17, 2019 7:47 PM -
User-1458727574 posted
Yeah, that's what I vaguely recall. Last time I did this was about 2010 so I'm a wee bit rusty :) Also, it turns out that my initial test posting to the endpoint was resulting in an error because they gave me the wrong endpoint address to the wrong WSDL. That doesn't help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 18, 2019 8:52 AM
All replies
-
User-1038772411 posted
For asmx you need to pass a stringified version of the data object, so for example:
var data = "{param1:" + param1IsANumber + ", param2:\"" + param2IsAString + "\"}"; $.ajax({ data: data, dataType: "json", url: url, type: "POST", contentType: "application/json; charset=utf-8", success: function (result) {} });
Or you can hava an object and use jquery-json
var data = {}; data.param1 = 1; data.param2 = "some string"; $.ajax({ data: jQuery.toJSON(data), dataType: "json", url: url, type: "POST", contentType: "application/json; charset=utf-8", success: function (result) {} });
Finally, your web service class must look like:
[WebService(Namespace = "http://www.somedomainname.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class MyService : System.Web.Services.WebService { [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public void MyServiceCall(int param1, string param2) { } }
Or,
You Want To Do This Using Window Application Kindly Refer Below Link
Thanks.
Monday, June 17, 2019 12:00 PM -
User1120430333 posted
Maybe, you are posting to the wrong forum, becuase there is a WCF, ASMX and other services ASP.NET forum you can post to for help.
Monday, June 17, 2019 3:51 PM -
User-1458727574 posted
Maybe. I did read down the list but obviously missed that forum.
Monday, June 17, 2019 3:55 PM -
User475983607 posted
So, assuming I have created the object, how do I go about sending that object to the end point and pick the response up?Creating a service reference generates all the "proxy" code you need to call the service in an object oriented manor. Then remote method arguments are usually just object that you fill. Intellisense should guide you. The same goes for the response, it will be an object in the generated file.
Creating a service reference is supposed to make calling a service end point just like calling a method.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 17, 2019 7:47 PM -
User-1458727574 posted
Yeah, that's what I vaguely recall. Last time I did this was about 2010 so I'm a wee bit rusty :) Also, it turns out that my initial test posting to the endpoint was resulting in an error because they gave me the wrong endpoint address to the wrong WSDL. That doesn't help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 18, 2019 8:52 AM -
User1724605321 posted
Hi ,
May i confirm that you have solved your issue ? You can try add a web service reference , In the dialog, just enter the location where you downloaded the WSDL file and a proxy will be generated for you :
https://www.c-sharpcorner.com/UploadFile/1d42da/web-service-basics/
https://www.guru99.com/wsdl-web-services-description-language.html
Best Regards,
Nan Yu
Wednesday, June 19, 2019 2:40 AM -
User-1458727574 posted
I had already created a web reference using the WSDL. The problem seemed to be the URL I was given was not functioning correctly.
Wednesday, June 19, 2019 9:14 AM