Calling a web service - asmx - through a Microsoft Web API endpoint?

I am using Microsoft ASP.NET Web API 2 , and one of my endpoints must internally call the deprecated asmx web service.

Is it correct?

 ................................................... WebRequest req = WebRequest.Create(myWebServiceURL); req.Method = "POST"; eq.ContentType = "application/x-www-form-urlencoded"; string postData = whateverDataNeedsToBePosted; using ( Stream reqStream = req.GetRequestStream() ) { reqStream.Write( new ASCIIEncoding().GetBytes( postData ), 0, postData.Length ); reqStream.Close(); } WebResponse resp = req.GetResponse(); 

................................................

UPDATE: I have a bunch of non-Microsoft web services (without asnx or svc). Is the above method good enough for these types of services?

+6
source share
1 answer

It will work, but you make your life difficult :)

You can add a service reference to your project in Visual Studio and call the methods in the ASMX service just as you would call methods in the specified DLL. See this article .

UPDATE:

Yes, your method for calling other services will work, but I would see if your other services will be added first, as links to services to your project. The service’s reference function works with all types of protocols (regardless of whether it is integrated into Microsoft technology or not).

+6
source

All Articles