The Easy Way to Use SvcUtil.exe with a Large Xml Schema

By Cory VandenBout on February 24, 2016

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.

 

 

Share This Post:

Twitter Pinterest Facebook Google+
Click here to read more Tutorials posts
Start a Project with Us

About the author

In an office of eccentric teammates, Cory brings the normal. Low key and mellow, Cory has been developing software for BizStream since 2006. He handles product development and support, and manages the company’s technology. In his off time, Cory is an all-star dodge ball player, and digs home automation, movies, and playing sports and games. He enjoys spending time with his wife Becky, daughter Zoe, and his cat Cocoa.

View other posts by Cory

Subscribe to Email

Enter your email address to subscribe to the BizStream Newsletter and receive updates by email.