문제

I am using Microsoft ASP.NET Web API 2 and one of my end points has to internally invoke a legacy asmx web service.

Is this the correct way?

...................................................
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 do have a bunch of non-Microsoft technology web services (no asnx or svc). Is the above method good enough for those type of services?

도움이 되었습니까?

해결책

That will work, but you're making your life difficult :)

You can add a Service Reference to your project in Visual Studio and call methods in the ASMX service just like you would call methods in a referenced DLL. See this article.

UPDATE:

Yes, your method for calling other services will work, but I would check to see if adding your other services as Service References to your project works first. The service reference feature works with all kinds of protocols (whether built with Microsoft technologies or not).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top