In the last post (WCF Proxy generation – using dotnet-svcutil)
we have seen how to generate WCF proxy code using dotnet-svcutil
.
You might have noticed that dotnet-svcutil has generated the collection types as arrays. For example, if the target service has any collection type in contract property like List<string>
,
then it is shown as array of string (string[]
) in generated code.
You have to tell dotnet-svcutil to use that collection type by specifying a collection type parameter ct
. But also you have to specify another reference parameter r
to provide full path for the
System.Collections
assembly, otherwise it will give you error.
First run this command without providing the assembly path for System.Collection
.
dotnet-svcutil https://localhost:8081/OrderManagement/OrderManagement.svc -ct "System.Collections.Generic.List`1"
You will get this error message:
Error: No type could be loaded for the value 'System.Collections.Generic.List1' passed to the --collectionType option. Ensure that the assembly this type belongs to is specified via the --reference option.
Now provide a valid assembly path for System.Collection
in r
parameter:
dotnet-svcutil https://localhost:8081/OrderManagement/OrderManagement.svc -ct "System.Collections.Generic.List`1" -r "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\ microsoft.netcore.app\2.2.0\ref\netcoreapp2.2\System.Collections.dll"
This command will create a Reference.cs
file within ServiceReference
folder, this time with collection type List<string>
rather than string[]
.
Note: If you are running this command from powershell you might still get above error. Try to run from Windows Command Prompt and it will run successfully.
References:
No comments:
Post a Comment