C#根據wsdl文件生成客戶端調用代碼,
要用到visaul studio的命令行工具。進入開始菜單visual studio的菜單,選擇 "visual studio tool",打開菜單里面命令提示符選項,輸入一下命令:
wsdl .\soapService.xml.wsdl /si /namespace:nsname /out:.\ISoapService.cs
這個命令生成服務端的接口文件,其中soapService.xml.wsdl是當前目錄的wsdl文件
如果要生成客戶端類文件,輸入一下命令:
wsdl .\soapService.xml.wsdl /namespace:nsname /out:.\SoapService.cs
一個完整的例子如下:
D:\>wsdl .\soapService.xml.wsdl /si /namespace:nsname /out:.\ISoapService.cs Microsoft(R) Web Services 描述語言實用工具 [Microsoft (R) .NET Framework, Version 2.0.50727.3038] Copyright (C) Microsoft Corporation. All rights reserved. 正在寫入文件“.\ISoapService.cs”。 D:\>wsdl .\soapService.xml.wsdl /namespace:nsname /out:.\SoapService.cs Microsoft(R) Web Services 描述語言實用工具 [Microsoft (R) .NET Framework, Version 2.0.50727.3038] Copyright (C) Microsoft Corporation. All rights reserved. 正在寫入文件“.\SoapService.cs”。 D:\>
關於參數:
/namespace:nsname 是指定命名空間為nsname, 如果需要修改,可以直接改為所需要的命名空間