Hi Guys,
Hopefully this is a fairly simple one... I need to call a web service from a c# class without actually added a web reference to the project. Obviously I need to handcraft some HttpRequests and interpret the responses manually, just want to know the best way to achieve this. Is there any base class in the framework that'll have a URL property and a method such as CallWebMethod(methodName, param object[] parameters)
Did do a search, but couldn't find anything that was quite what I wanted to achieve.
Thanks in advance,
Simon.

How to call a web service without adding a web reference...
TimToennies
All XML Web service client proxies auto-generated by wsdl.exe derive from the System.Web.Services.Protocols.HttpWebClientProtocol class. If your desire is to handcraft your own proxy, I would suggest deriving from this class.
Could you elaborate as to why you do not wish to add a Web reference to your project
Martijn Kieboom
I also face similiar situation where i need to create the web reference on run time.
Can you explain how you acchive this..
I creating a class/dll to allow user access methods from web service but user will pass url,server name and other parameters for me to create web reference.
MiCR0
Ok, I've got the base class I was talking about!
I have this test code so far:
[System.Web.Services.WebServiceBindingAttribute(Name = "ServiceSoap", Namespace = "http://tempuri.org/",Location="http://localhost/swiftpassservice/service.asmx")]
internal class GenericWebServiceProxy : SoapHttpClientProtocol
{
public GenericWebServiceProxy(string url)
{
this.Url = url;
}
public string CallWebMethod(string methodName, params object[] parameters)
{
object[] o = Invoke(methodName, parameters);
return o.ToString();
}
However, whatever method I call on the webservice, I get the following exception:
Exception Details: System.ArgumentException: {MethodName} Web Service method name is not valid.
Anyone have an idea how to fix this
Thanks again.
mack0196
Thanks, I have sorted the issue now. The webservice methods that I need to call, must also be stubbed out in the generic proxy class and decorated with the SoapDocumentMethod Attribute.
This reason I didn't want the webservice added as a reference is because the call to the webservice is inside a server control, and a requirement is that the url is a property of this control.
Oh dear, I've just realised I could have just as easily amended the URL property of the auto-generated proxy class in the control initialization! Doh! Not sure why I didn't think of that - at least I know how to create a generic web service proxy now though!! :-)
Thanks for your help.
Simon.
Nocsaron
You need to specify the SOAPAction HTTP header field for CallWebMethod. This can be through either of the listed attributes. The SOAPAction tells the request which function is going to be called on the server.
http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soaprpcmethodattribute.aspx
http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.soapdocumentmethodattribute.aspx
[SoapDocumentMethod(action= \"http://tempuri.org/methodName\")]
ChasWorth
Hi BALA SINGAM,
You can do as described above but you're going to run into management issues as time goes by especially if these service definitions change often. You'll have to manually change it unless you come up with a better method.
Dellendinho (http://dellendinho.blogspot.com)
skaranam
Thanks for the reply. My situation is like this, i need build a dll/library to support Reporting Services report management through reporting services soap methods.
The reporting server might sit on different machine cause developement and production environment.
I can't hard code the web reference cause i dunno what is the machine name in production,in other way i should give users the flexibity to connect their prefered reporting server.
Regards
Bala Singam
Neil_F
You may want to look into WCF. ChannelFactory<T> in WCF allows you to call Services without generated proxies.