Common WCF types in WSDL

I need to use several separate web services from the same provider. Basically, each function has its own service (wsdl). For interop, each wsdl has links for common types (for example: xs: import namespace = "http://generic.type.com"]).

Adding service references to VS will prefix the service namespace for these types. Adding two services will result in two separate but identical classes:

var context = new Service1.GenericContext(); var contex2 = new Service2.GenericContext(); 

How can I match / combine them? I have 20 of these services.

Illustrated namespace in Reference.svcmap, but with an error. I do not know what to use TargetNamespace and ClrNamespace.

ty!

+4
source share
1 answer

Instead of adding service references, you should use svcutil.exe to create a service proxy file for one endpoints together.

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

Then the svcutil.exe call has many parameters. Therefore, I recommend that you store it in a batch file or even more comfortably: place the command call in the "Build Events" section in Visual Studio in the "Prebuild Event Command Line".

Here is the svcutil call for my client, which combines all the proxy classes in ServiceProxy.cs. Most likely, you need to change 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 if you do not add this to the bottom of your .csproj file right above the Project closing element:

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

Source: https://habr.com/ru/post/1390074/


All Articles