Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet packages: how to add references to webservices?

I am creating a NuGet package, where I would like to use two web services.

I started by adding manually the files for the services and modifying config file. But while I was going through the files and correcting the references, I understood that this approach is not productive, especially, if later I would need update the webservices and references. I googled for solutions, but barely found anything helpful.

Thus, my question is, what is a correct approach to add references to the webservices into NuGet packages?

Thank you.

like image 222
Anelook Avatar asked Oct 22 '22 05:10

Anelook


2 Answers

The approach I selected was to use svcutil to generate proxy class for the Web service. Then I was able to either use this proxy class to access webservice, or to go farther and create dll based on it and reference this dll in the targeted project.

In case it can be useful to someone, here is the powershell code which creates proxy class and dll based on a webservice url:

$className = "SomeClass";
$svcUri = "http://.../SomeWebService.svc?wsdl";
$csFile = $className + '.cs';  
$dllName = [System.IO.Path]::Combine($temp, $className + ".dll")
$svcUtilresult =  & svcutil.exe /noConfig /out:$csFile $svcUri
csc.exe /t:library /out:$dllName $csFile
like image 173
Anelook Avatar answered Oct 23 '22 19:10

Anelook


You can use wsdl.exe. If you have Visual Studio installed then you should be able to find it here C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin or a similar path depending on your precise version.

The microsoft documentation is pretty straightforward https://msdn.microsoft.com/en-us/library/7h3ystb6%28VS.80%29.aspx.

I have found that this works better for asmx web services, as the static classes that it generated are a precise match for the classes generated by using the Add Web Service / Update Web Service functionality within Visual Studio. All you need to do is add the .cs files generated by the tool into your project and remove your web references. You may need to update your using references to the new namespace, but that is all.

The static classes generated by svcutil.exe are a better fit for WCF services, that tool is located in the same directory, if you need to find it from the command line.

like image 34
ste-fu Avatar answered Oct 23 '22 19:10

ste-fu