質問

Our customer sent us a WSDL file for their web service API. We used Visual Studio's "Add Service Reference" to consume it.

However: we only want to generate a service proxy, not the data contract classes. We want to reuse classes we already have within a referenced assembly.

  • How to instruct "Add Service Reference" to not create Data Contract classes?
  • ...or how to instruct WCF to use our Data Contract classes from the referenced assembly instead?
役に立ちましたか?

解決

This comes down to the following options on the Advanced... part of "Add Service Reference":

enter image description here

which also map to the /r / /reference option in svcutil.exe.

This defaults to enabled, so if it isn't working: there's a good chance your types are not exact matches. The easiest way to ensure exact matches is to reference the same library dll from both projects, or worst case the same .cs file (a dll reference would be preferable, IMO). The data-contract namespace and name are the usual culprits here, and must match exactly (as must the members).

他のヒント

Add your data contract classes (or even better create a new library for you data contract classes and reuse both in the service and client side) to the project including your service references. When adding a new service reference or updating an existing one, select "Reuse Types in Referenced Assemblies".

This is old but I have one doubt about this. I can access classes when adding service reference, this is ok I can't see these classes when working with all projects inside the same solution in Visual Studio and adding "project" references.

Is there a way to test client side code using all projects inside the same solution in Visual Studio?

thanks

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top