LZW
LZW

Reputation: 1045

WCF shared types in WSDL

I have to use several separate webservices from the same provider. Basicly every function has its own service (wsdl). For interop every wsdl has references for shared types (ex: xs:import namespace="http://generic.type.com" />).

Adding Service Referances in VS will prefix the service namespace to these types. Adding two services will generate two separate but identical class:

var context = new Service1.GenericContext();

var contex2 = new Service2.GenericContext();

How can I map/cast these together? I have 20+ services like this.

Tried NamespaceMappings in Reference.svcmap, but faild. I don't know what TargetNamespace and ClrNamespace to use.

ty!

Upvotes: 4

Views: 938

Answers (1)

mono68
mono68

Reputation: 2090

Instead of adding service references you should use svcutil.exe to generate one service proxy file for the endpoints all together.

All service proxy classes are then together in the same namespace you specify with the command line switch /n.

The svcutil.exe call has many parameters then. So I recommend you store it in a batch file or even more comfortable: Place the command call under Build Events in Visual Studio into "Pre-build event command line".

Here is the svcutil call for my client which puts all proxy classes together in ServiceProxy.cs. Most likely you have to modify the path to svcutil.exe and of course the service URLs:

"%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0A\bin\svcutil.exe" /noLogo /noConfig /out:"$(ProjectDir)ServiceProxy.cs" /t:code /i /l:cs /tcv:Version35 /ser:DataContractSerializer /ct:System.Collections.Generic.List`1 /n:*,Oe.Corporate.CRMFacade.Service.Test http://localhost:3615/Client010/MasterDataService.svc http://localhost:3615/Client010/BusinessPartnerService.svc http://localhost:3615/Client010/MarketingAttrService.svc http://localhost:3615/Client010/ProductTransactionService.svc http://localhost:3615/Client010/ProductDataService.svc http://localhost:3615/Client010/ActivityManagementService.svc http://localhost:3615/Client010/PromotionService.svc

UPDATE: I forgot to mention that the pre-build event will fail unless you add this to the bottom of your .csproj file right above the closing Project element:

<Target Name="PreBuildEvent" Condition="'$(PreBuildEvent)'!=''" DependsOnTargets="$(PreBuildEventDependsOn)">
    <Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" ContinueOnError="true" />
</Target>

Upvotes: 2

Related Questions