Introduction:
In this we are discussing about how to invoke a particular ws web method without adding the Web Reference.
Main:
We configured the webservice url and web method name in app.config,and created one Webserviceclient for invoking the webmethod.Is this something same like httppost method,but in http post we will send request in xml format.
string WebServiceUrl=ConfigurationSettings.AppSettings["wsurl"].ToString(); string WebMethod=ConfigurationSettings.AppSettings["wsmethod"].ToString(); WebServiceClient ServiceClient = new WebServiceClient(); System.IO.Stream stream = ServiceClient.OpenRead(WebServiceUrl + "?wsdl"); ServiceDescription ServiceDesc = ServiceDescription.Read(stream); ServiceDescriptionServiceimp Serviceimp = new ServiceDescriptionServiceimp(); Serviceimp.ProtocolName = "Soap12"; Serviceimp.AddServiceDescription(ServiceDesc, null, null); Serviceimp.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties; CodeNamespace ServiceNameSpace = new CodeNamespace(); CodeCompileUnit CombileUnit = new CodeCompileUnit(); CombileUnit.Namespaces.Add(ServiceNameSpace); ServiceDescriptionImportlocal_warnings local_warning = Serviceimp.Import(ServiceNameSpace, CombileUnit); if (local_warning == 0) { string[] assemblyReferences = new string[2] {"System.Web.Services.dll","System.Xml.dll"}; CompilerParameters locaol_params = new CompilerParameters(assemblyReferences); Compilerresults local_results = provider1.CompileAssemblyFromDom(locaol_params, CombileUnit); if (local_results.Errors.Count > 0) { System.console.writeline("Combile Error"); } object obj = this.webServiceAssembly.CreateInstance(serviceName); MethodInfo local_info = obj.GetType().GetMethod(WebMethod); return local_info.Invoke(obj,args); } else { return null; } } |
Conclusion:
Hope,this helps.
Happy Coding.
Instead the reference must be made to the parent document. Web Service
You’re soooo gifted in writing. God is truly utilizing you in miraculous methods. You are doing a excellent job! This was an awesome weblog!
Thanks for sharing this excellent post, i truly adore your weblog, but i’ve some issue i dont know whether it’s my side problem or in your site? some words of the submit in your weblog have charactor encoding problem, yes i use auto detecting, can u pls look into this issue a bit?
Advantageously, the article is really the best topic on this related issue. I fit in with your conclusions and will thirstily look forward to your approaching updates. Just saying thanks will not just be adequate, for the wonderful clarity in your writing. I will at once grab your rss feed to stay privy of any updates.
Great site. A lot of useful information here. I’m sending it to some friends!
Congratulations for posting such a useful weblog. Your weblog is not only informative but also extremely artistic too. There normally are extremely couple of individuals who can write not so easy articles that creatively. Keep up the great work !!
That is nice to definitely find a site where the blogger knows what they are talking about.
Good work! Thanks for such interesting writing as I had been in a position to find here. I agree with most of what is written the following and I am going to be coming back to this site again.
Hei, I like this blog, many good information, I want to subscribe it, can anyone help me?