The Easy Way to Use SvcUtil.exe With a Large XML Schema

If you’ve ever used SvcUtil.exe to generate even a slightly complicated WCF Service, you know how annoying it is to gather up all your imported Xsd’s and list them after the command. I have no idea why, but SvcUtil.exe is too stupid to be able to figure out relative links on your local filesystem. Take heart, however, there are a few different ways to let SvcUtil know about your XML schema.

The Hard Way

Go through each and every imported WSDL and XSD file, making a list of all the full paths to each imported file. As you probably know, since you’ve Googled this far, this can be super annoying and time-consuming when you have a large XML schema.

The Extra Code Way

Write a little utility app to do the heavy lifting for you. Recursively parse the text of each file, storing the full path and finding more files to parse. This is ok, but it just forces you to write and maintain more code.

The Easy Way

While SvcUtil.exe can’t seem to figure out relative links on your local filesystem, it seems to have no problem when your schema is hosted. A quick and easy way to take advantage of this is to create a local IIS website with your schema as the Physical Path. Then, when you pass your WSDL to SvcUtil, you use the URL instead. Bingo, all your relatively linked XSD files are picked up and your service is created!

Using the easy way, your SvcUtil.exe command goes from this:

				
					svcutil.exe /n:*,MyNamespace /out:IMyService.cs 
"D:\Service SSP\service-specifications\My_Request_Service\schema\SIP_WS_1.2\My_Request_Service.wsdl" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\access-denial.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\exchange_schema.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\extension_schema.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\search-request-error-reporting.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\search-results-metadata.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\impl\michigan\michigan-codes.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\domains\cyfs\2.1\1\cyfs.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\domains\intelligence\2.1\intelligence.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\domains\jxdm\4.1\jxdm.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\fbi\2.0\fbi.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\fips_10-4\2.0\fips_10-4.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\fips_5-2\2.0\fips_5-2.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\niem-core\2.0\niem-core.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\post-canada\2.0\post-canada.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\proxy\xsd\2.0\xsd.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\structures\2.0\structures.xsd" 
"D:\Service SSP\service-specifications\My_Request_Service\artifacts\service_model\information_model\My_Request_Service_IEPD\xsd\Subset\niem\unece_rec20-misc\2.0\unece_rec20-misc.xsd"
				
			

to this:

				
					svcutil.exe /n:*,MyNamespace /out:IMyService.cs “http://local-ssp.com/service-specifications/My_Services/schema/SIP_WS_1.2/MyRequestInterface.wsdl”
				
			

That's It

As you can see it is a lot nicer only having to worry about loading in your resources from the URL-based version.

About the Author

Cory Vandenbout

In an office of eccentric teammates, Cory brings the normal. Low key and mellow, Cory has been developing software for BizStream since 2006 and leads the development team for YouthCenter and CaseStream, two of our products. In his off time, Cory digs home automation, movies, and plays sports and games. He enjoys spending time with his wife Becky, daughters Zoe and Ella, and his dog Leia.

Subscribe to Our Blog

Stay up to date on what BizStream is doing and keep in the loop on the latest in marketing & technology.