Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core 2.0 Issue in creation an instance of derived class of Client base for Consuming WCF service using System.servicemodel.Primitives #2293

Closed
pardhumeduri opened this issue Sep 18, 2017 · 16 comments
Labels
bug This is a product bug.
Milestone

Comments

@pardhumeduri
Copy link

we don't want to go with proxy generation approach for consuming WCF services.
We have tried to call the WCF using System.servicemodel.Primitives and deriving from clientBase class.
however when we try to create instance of child class of Clientbase it is giving the following error

System.PlatformNotSupportedException: 'Configuration files are not supported.'

image

@zhenlan
Copy link
Member

zhenlan commented Sep 19, 2017

Hi @pardhumeduri sorry for running into this. WCF on .NET Core does not support configuration, so as the error suggested, please choose other constructors of ClientBase that does not take configuration.

@zhenlan zhenlan added this to the S124 milestone Sep 19, 2017
@pardhumeduri
Copy link
Author

Hi Zhenlan

i am able to fix this issue after changing the constructor to use binding, EndPoint, however getting the following issue, kindly let us know if there any way we can consume WCF services in Core 2.0 wihthout generating proxy classes.
Also please share if we have any samples solutions on how to consume wcf in core 2.0 without WCF connectivity tool ( proxy)
image

@pardhumeduri
Copy link
Author

i am able to fix this issue after changing the constructor to use binding, EndPoint, however getting the following issue, kindly let us know if there any way we can consume WCF services in Core 2.0 wihthout generating proxy classes.
Also please share if we have any samples solutions on how to consume wcf in core 2.0 without WCF connectivity tool ( proxy)
30658127-c0da41c6-9e07-11e7-8afc-0f094768d0d6

@zhenlan
Copy link
Member

zhenlan commented Sep 25, 2017

Hi, @pardhumeduri I am glad you are able to make progress.

kindly let us know if there any way we can consume WCF services in Core 2.0 wihthout generating proxy classes.

Certainly, you don't have to use the tool to generate the proxy code (using ClientBase etc.). Here is an example that uses BasicHttpBinding and calls a simple Echo service on the server. Is it helpful to you? Please feel free to explore other tests for more complex scenarios.
https://github.com/dotnet/wcf/blob/master/src/System.Private.ServiceModel/tests/Scenarios/Binding/Http/BasicHttpBindingTests.4.0.0.cs

@zhenlan zhenlan modified the milestones: S124, S125 Sep 29, 2017
@pardhumeduri
Copy link
Author

hi Zhenlan

I have done the following steps

  1. Created WCF service in .Net 4.5.2
  2. Hosted it in IIS
  3. using ChannelFactory option tried to consume the service in Core 2.0
    it worked , i am able to hit the .net4.5.2 wcf service from Core 2.0 console application However if we add reference to some of the .net4.5.2 dlls ( models dll which was part .net 4.5.2) and tried to use those models in generating request and response then we are facing "system.servicemodel.dll" not found issue. Please suggest how we can proceed further.

{System.InvalidOperationException: An error occurred while loading attribute 'OperationContractAttribute' on method 'test' in type 'TestService'. Please see InnerException for more details. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
at System.ServiceModel.Description.CustomAttributeProvider.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(CustomAttributeProvider attrProvider, Type attrType, Boolean inherit)
--- End of inner exception stack trace ---
at System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(CustomAttributeProvider attrProvider, Type attrType, Boolean inherit)
at System.ServiceModel.Description.ServiceReflector.GetCustomAttributes(CustomAttributeProvider attrProvider, Type attrType)
at System.ServiceModel.Description.ServiceReflector.GetSingleAttribute[T](CustomAttributeProvider attrProvider)
at System.ServiceModel.Description.ServiceReflector.GetOperationContractAttribute(MethodInfo method)
at System.ServiceModel.Description.TypeLoader.CreateOperationDescription(ContractDescription contractDescription, MethodInfo methodInfo, MessageDirection direction, ContractReflectionInfo reflectionInfo, ContractDescription declaringContract)
at System.ServiceModel.Description.TypeLoader.CreateOperationDescriptions(ContractDescription contractDescription, ContractReflectionInfo reflectionInfo, Type contractToGetMethodsFrom, ContractDescription declaringContract, MessageDirection direction)
at System.ServiceModel.Description.TypeLoader.CreateContractDescription(ServiceContractAttribute contractAttr, Type contractType, Type serviceType, ContractReflectionInfo& reflectionInfo, Object serviceImplementation)
at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation)
at System.ServiceModel.Description.TypeLoader.LoadContractDescription(Type contractType)
at System.ServiceModel.ChannelFactory1.CreateDescription() at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address) at System.ServiceModel.ChannelFactory1..ctor(Binding binding, EndpointAddress remoteAddress)
at CoreWCFClient.Program.CheckAuthenticateService(String strServer, String strBinding, Int32 nPort, String strOper, String userID, Double dblVal2) in c:\users\u1jca83\documents\visual studio 2017\Projects\CoreWCFClient\CoreWCFClient\Program.cs:line 151}

@zhenlan
Copy link
Member

zhenlan commented Sep 30, 2017

Good to see further progress. In your .NET Core 2.0 app, you should not reference assemblies from the full framework (eg. 4.5.2). May I know why you need to do this?

@pardhumeduri
Copy link
Author

we have some applications in .Net 4.5.2 which we is source for .Net Core 2.0 application. We get the MVC Models from .Net 4.5.2 which is common models for Core and .Net applications. we do not want re create model solution in core because if any changes done in source will not be in sync. hence we wanted to refer .Net 4.5.2 dlls in core 2.0

@pardhumeduri
Copy link
Author

we have tested the .net4.5.2 dll reference in Core 2.0 web and console application we are able to use the models in them, however when we try to do the same with WCF services then we are facing system.servicemodel.dll" not found issue.

@zhenlan
Copy link
Member

zhenlan commented Nov 11, 2017

@pardhumeduri this is because a shim that forwards WCF APIs from full framework to .NET Core was missing. We are rebuilding System.ServiceModel.Primitives package to include this shim (#2375) and hopefully, we can have the package released soon after testing etc. (in weeks). In the meanwhile, it will be great if you can give the package built out of master branch a try to see if it fixes your issue.

@zhenlan zhenlan modified the milestones: S125, S127 Nov 11, 2017
@zhenlan
Copy link
Member

zhenlan commented Nov 21, 2017

@pardhumeduri we just released to nuget.org an update of System.ServiceModel.Primitives package, which contains the System.ServiceModel.dll shim you would need. Can you please update your project to reference this package and see if it solves your problem?

https://www.nuget.org/packages/System.ServiceModel.Primitives/4.4.1-servicing-25917-01

@pardhumeduri
Copy link
Author

pardhumeduri commented Nov 21, 2017 via email

@zhenlan zhenlan modified the milestones: S127, S128 Dec 1, 2017
@Joebeazelman
Copy link

@zhenlan I am getting a critical error and the shim doesn't work. The UWP version doesn't work either.

#2438

@zhenlan
Copy link
Member

zhenlan commented Jan 20, 2018

A stable version of System.ServiceModel.Primitives package that has the fix of this issue has been released early last week.
https://www.nuget.org/packages/System.ServiceModel.Primitives/4.4.1

@Elvin1492
Copy link

A stable version of System.ServiceModel.Primitives package that has the fix of this issue has been released early last week.
https://www.nuget.org/packages/System.ServiceModel.Primitives/4.4.1

The problem still is not solved

@james-novino
Copy link

@zhenlan This issue is still an issue even when referencing System.ServiceModels.Primitives >= 4.5.3. Any guidance on solving that issue.

@JacobSchnedler
Copy link

I solved this by explicitly specifying the binding and the endpointAddress. My understanding is; if given all parameters, there is no need to look for a configuration file - which is the culprit.

This, of course, rests on the availabily of a constructor, which allows your to explicitly configuring the consumerclient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a product bug.
Projects
None yet
Development

No branches or pull requests

6 participants