views:

22

answers:

2

When using an HTTPWebRequest object to call a web service, and supply the wsdl parameter, I get the description page ok.

Dim req As Net.HttpWebRequest
Dim resp As Net.HttpWebResponse
Dim sr As IO.StreamReader
Dim text As String

req = Net.WebRequest.Create("http://www.mysite.com/DS.asmx?wsdl") ' works '
resp = req.GetResponse
sr = New IO.StreamReader(resp.GetResponseStream)
text = sr.ReadToEnd

However, when I attempt to call one of the methods using the reference showing as the soapAction, I get (404) Not Found.

req = Net.WebRequest.Create("http://mysite.com/DS/StaffList") ' fails '

Is there a difference in the way a method should be called that I'm missing? Am I misinterpreting the structure of the address?

Note: The service works fine if I set a standard WebReference in the Visual Studio project and call the method on the WebService object, so the service itself is available and working.

+1  A: 

In order to invoke a SOAP web service you will need to POST a XML request in a SOAP envelope. That's what the generated classes using WebReference do behind the scenes. Unless you have a compelling reason you should never invoke a SOAP web service using the low level classes such as HttpWebRequest but generate a proxy from the WSDL using Add WebReference.

Take a look at this MSDN article. Also note that classic ASMX web services is now considered a deprecated technology and should be replaced by WCF.

Darin Dimitrov
A: 

You are trying a pre-WCF web service. If migrating to a WCF service is an option, you can map the service to RESTful enpoints.

REST (Representational State Transfer) is used (among other options) to describe function calls in URL structures, without additional content such as SOAP.

gimel