svcutil exlude/reuse refrenced assemblies

余生颓废 提交于 2019-12-18 03:43:59

问题


Is it possible to use svcutil to reuse/exclude referenced types, as with visual studio.

I have multiple projects, my types/datamodels are stored in separate assemblies, so they can be used by other non wcf projects etc. When updating refrences in the visual studio gui, this all works out just fine. As long as a type is found on both sides of the border, it's excluded from beeing defined in the proxy.

How can I achieve the same thing using svcutil?

More clearly I want to generate the proxy from a dll, not a running service which contains the servicecontract. At the same time I want to feed the dll files containing the shared types, which should be excluded from beeing defined in the proxy.

The reason for all this is for allowing my projects to be updated and built on a buildserver.

Edit: First of thank you for your reply and suggestion of parameters. However I'm not getting svcutil reusing the assemblies following your instructions.

Here is parts of the .bat file I made I've excluded all the flags for generating INotifyPropertyChanged etc.

SET BACKENDROOT=C:\SomePath\Development\Backend\bin
SET DATAMODELSBASE=C:\SomePath\Development\DataModels\bin
SET COMMONBASE=C:\SomePath\Development\Common\bin

SET REFRENCED_ASSEMBLIES=/r:%DATAMODELSBASE%\Jall.DataModels.Consignment.dll

svcutil %BACKENDROOT%\Jall.Backend.Consignment.DLL /t:metadata
svcutil /o:test.cs %REFRENCED_ASSEMBLIES% *.wsdl *.xsd

The result is as follows:

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
   [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/KSD.DataModels.Consignment")]
public partial class ExtInvoice : OrmBase
{

private System.DateTime buyersOrderDateField;

private bool buyersOrderDateFieldSpecified;

private string buyersOrderNumberField;

private string compCodeField;
.....

And in the client it self:

public Address CreateNewAddress(int TK, string AddressType)

This is incorrect the datamodels are generated directly in the proxy. The client doesn't just skip them and use the proper namespace for the types. The correct result should be:

public Jall.DataModels.Consignment.Address CreateNewAddress(int TK, string AddressType)

(Names are scrambeled :) )

Brgds, Stian


回答1:


svcutil /?

gives

/reference:<file path> - Add the specified assembly to the set of assemblies 
                         used for resolving type references. If you are 
                         exporting or validating a service that uses 3rd-party
                         extensions (Behaviors, Bindings and BindingElements)
                         registered in config use this option to locate 
                         extension assemblies that are not in the GAC.  
                         (Short Form: /r)

So running svcutil with /r:myassembly.dll should make it.




回答2:


Thanks for your help. Got this working eventually with the following commands:

SET BACKENDROOT=C:\SomePath\Development\Backend\bin
SET DATAMODELSBASE=C:\SomePath\Development\DataModels\bin
SET OUTFOLDER=C:\SomeOutputFolder
SET REFRENCED_ASSEMBLIES=/r:%DATAMODELSBASE%\Jall.DataModels.Consignment.dll
SET REFRENCED_ASSEMBLIES=%REFRENCED_ASSEMBLIES% /r:%DATAMODELSBASE%\Jall.DataModels.SomethingElse.dll

SET SVCFLAGS=/enableDataBinding /s /a /tcv:Version35

::Generate metadata
svcutil %BACKENDROOT%\Jall.Backend.Consignment.DLL /t:metadata -d:%OUTPUTFOLDER%

::Generate proxy with shared types
svcutil %OUTPUTFOLDER%\*.wsdl %OUTPUTFOLDER%\*.xsd %SVCFLAGS% /ser:DataContractSerializer %REFERENCED_ASSEMBLIES /o:test.cs

Note that the /ser:DataContractSerializer had to be used for this to work. And another annoyance is that if types such as datatables/datasets etc is used (not that they really should though) their assemblies have to be included or svcutil will mess up generating the metadata.

IE:

SET SHAREDASSEMBLIES=%SHAREDASSEMBLIES% /r:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll



回答3:


If you run svcutil without arguments, you'll see it has several functions. I think you could do what you want with two invocations:

  • One to generate metadata from your binary, with a command line like svcutil /serviceName:<myServiceName> <pathToAssemblyWithConfigFile>. This outputs .wsdl and .xsd files.
  • Another to generate code from the metadata, with switches specifying where to find existing types for the data contracts: svcutil /reference:<assemblyPath> *.wsdl *.xsd.

I've tried doing this in one step before, but when svcutil is in "code generation" mode, it expects metadata as input, not assemblies. So generate metadata first!



来源:https://stackoverflow.com/questions/8786096/svcutil-exlude-reuse-refrenced-assemblies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!