我想从WCF客户端使用一些(非.Net)Web服务。
我有所有这些服务的WSDL文件。每个引用相同的XSD文件,定义所有类型。
在这种情况下,我不知道如何正确处理svcutil.exe。
如果我跑:
svcutil.exe WS1.wsdl types.xsd
效果很好。
如果我运行以下某项操作,则会失败:
svcutil.exe *.wsdl types.xsd
svcutil.exe ws1.wsdl ws2.wsdl types.xsd
svcutil.exe ws1.wsdl types.xsd
svcutil.exe ws2.wsdl types.xsd
(这个适用于两行,但是当我编译时,类型被定义多次)
svcutil.exe /ImportXmlTypes types.xsd
// Compile a VS Project this the types.Cs file
svcutil.exe ws1.wsdl /r:types.dll
由于每个服务使用相同的结果类型,我不想重复代码(即我不能为所有服务提供不同的“结果”类型)。
我有什么选择? 我正在努力解决这个简单的问题...
事先提前[编辑]关于我的问题的可能原因是所有服务都定义了相同的portName:
<service name="service 1">
<port name="lbWebPort" binding="y:lbWebBinding">
<soap:address location="xxx"/>
</port>
</service>
...
<service name="service 2">
<port name="lbWebPort" binding="y:lbWebBinding">
<soap:address location="xxx"/>
</port>
</service>
答案 0 :(得分:2)
我终于能够使用可怕的PowerShell脚本取消所有内容。
关键思想是为所有服务指定自定义命名空间。 但是由于某些部分(返回类型)在所有服务中共享,我不得不从XSD中提取类型并引用它。过程就是这个过程:
/r:Temp.dll
删除temp.dll文件
$web = new-object System.Net.WebClient
$currDir = (get-item WSDefinition).FullName
if($false) // Set to true if wsdl changed
{
$web.DownloadFile("http://urlofmywebservice/majClient/lbWebPort?wsdl","$currDir\CustomerServiceMajClientImpl.wsdl")
$web.DownloadFile("http://urlofmywebservice/lotClient/lbWebPort?wsdl","$currDir\CustomerServiceLotClientImp.wsdl")
$web.DownloadFile("http://urlofmywebservice/interlocuteur/lbWebPort?wsdl","$currDir\CustomerServiceInterlocuteursImp.wsdl")
$web.DownloadFile("http://urlofmywebservice/cdeConf/lbWebPort?wsdl","$currDir\CustomerServiceCdeConfirmationImp.wsdl")
$web.DownloadFile("http://urlofmywebservice/cdeLignes/lbWebPort?wsdl","$currDir\CustomerServiceCdeLignesImp.wsdl")
$web.DownloadFile("http://urlofmywebservice/cdeTete/lbWebPort?wsdl","$currDir\CustomerServiceCdeTeteImp.wsdl")
$web.DownloadFile("http://urlofmywebservice/majDevis/lbWebPort?wsdl","$currDir\CustomerServiceDevisImp.wsdl")
}
$svcutil = get-item ((get-item 'Env:\ProgramFiles(x86)').Value + "\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\svcutil.exe")
$csc = get-item ((get-item 'Env:\SystemRoot').Value + "\Microsoft.NET\Framework64\v4.0.30319\csc.exe")
& $svcutil WSDefinition\CustomerServiceTypes.xsd /importxmltypes /i /dconly /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer" /o:MyCustomer\Types.cs
& $csc /target:library /out:temp.dll MyCustomer\Types.cs
& $svcutil WSDefinition\CustomerServiceMajClientImpl.wsdl WSDefinition\CustomerServiceTypes.xsd /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.MajClient" /o:MyCustomer\MajClient.cs /s /tcv:Version35 /r:temp.dll
& $svcutil WSDefinition\CustomerServiceLotClientImp.wsdl WSDefinition\CustomerServiceTypes.xsd /mergeconfig /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.LotClient" /o:MyCustomer\LotClient.cs /s /tcv:Version35 /r:temp.dll
& $svcutil WSDefinition\CustomerServiceInterlocuteursImp.wsdl WSDefinition\CustomerServiceTypes.xsd /mergeconfig /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.Interlocuteurs" /o:MyCustomer\Interlocuteurs.cs /s /tcv:Version35 /r:temp.dll
& $svcutil WSDefinition\CustomerServiceCdeConfirmationImp.wsdl WSDefinition\CustomerServiceTypes.xsd /mergeconfig /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.CdeConfirmation" /o:MyCustomer\CdeConfirmation.cs /s /tcv:Version35 /r:temp.dll
& $svcutil WSDefinition\CustomerServiceCdeLignesImp.wsdl WSDefinition\CustomerServiceTypes.xsd /mergeconfig /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.CdeLignes" /o:MyCustomer\CdeLignes.cs /s /tcv:Version35 /r:temp.dll
& $svcutil WSDefinition\CustomerServiceCdeTeteImp.wsdl WSDefinition\CustomerServiceTypes.xsd /mergeconfig /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.CdeTete" /o:MyCustomer\CdeTete.cs /s /tcv:Version35 /r:temp.dll
& $svcutil WSDefinition\CustomerServiceDevisImp.wsdl WSDefinition\CustomerServiceTypes.xsd /mergeconfig /config:MyCustomerServices.config /mc /a /i /n:"*,MyCustomer.Project.Interfaces.Erp.WebServices.MyCustomer.Devis" /o:MyCustomer\Devis.cs /s /tcv:Version35 /r:temp.dll
Remove-Item temp.dll