wcf icon indicating copy to clipboard operation
wcf copied to clipboard

Exception when using proxy generated with the WCF Web Service Reference tool: There was an error reflecting 'data'

Open pewing1895 opened this issue 8 years ago • 17 comments

Hi,

When we try to use a specific connected service (soap) proxy class in a core 2.0 app, we receive an exception on calling any method from the class. (This service works fine in a .NET framework app)

It looks like the .net core class has been generated with several MessageBodyMemberAttribute that have a Namespace="" which seem to be the cause of the error. I have included the wsdl and a sample .net core project.

The question we have is whether the problem is with the wsdl or is it a bug in the core WCF connected service tool?

Thanks,

Exception:

System.InvalidOperationException HResult=0x80131509 Message=There was an error reflecting 'data'. Source=System.Private.Xml StackTrace: at System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.XmlSerializerImporter.ImportMembersMapping(XmlName elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean isEncoded, String mappingKey) at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, String mappingKey) at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector.LoadBodyMapping(MessageDescription message, String mappingKey, MessagePartDescriptionCollection& rpcEncodedTypedMessageBodyParts) at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector.CreateMessageInfo(MessageDescription message, String key) at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.OperationReflector.EnsureMessageInfos() at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.EnsureMessageInfos() at System.ServiceModel.Description.XmlSerializerOperationBehavior.CreateFormatter() at System.ServiceModel.Description.XmlSerializerOperationBehavior.System.ServiceModel.Description.IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy) at System.ServiceModel.Description.DispatcherBuilder.BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch) at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters) at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose) at System.ServiceModel.ChannelFactory.OnOpening() at System.ServiceModel.Channels.CommunicationObject.d__79.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.ServiceModel.Channels.CommunicationObject.d__78.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.ServiceModel.ChannelFactory.EnsureOpened() at System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ClientBase1.get_Channel() at CardManagementWS.CardManagementEPClient.loginAsync(String user, String password) in c:\users\com381\source\repos\msTestCaseShellWs\msTestCaseShellWs\Connected Services\CardManagementWS\Reference.cs:line 17459 at msTestCaseShellWs.Program.Main(String[] args) in c:\users\com381\source\repos\msTestCaseShellWs\msTestCaseShellWs\Program.cs:line 16

Inner Exception 1: InvalidOperationException: The top XML element 'data' from namespace '' references distinct types CardManagementWS.WSIssueNewPayrollCardData and CardManagementWS.WSIssueNewPersonalizedPayrollCardData. Use XML attributes to specify another XML name or namespace for the element or types.

CardManagement.wsdl.txt Program.cs.txt

pewing1895 avatar Jan 03 '18 17:01 pewing1895

Hi @pewing1895

Thank you for reporting this issue. We will investigate as soon as we have a chance.

Miguel Lacouture

mlacouture avatar Jan 08 '18 20:01 mlacouture

Looks like I am using the exact Card Management API; I'm getting the same error messages on the same distinct types: CardManagementWS.WSIssueNewPayrollCardData and CardManagementWS.WSIssueNewPersonalizedPayrollCardData.

I am using .Net Core 2.2 (Microsoft.AspNetCore 2.2.0)

I am looking into manually running dotnet-svcutil with different parameters in hopes that it can generate a suitable proxy but this is going to be a showstopper for me unless this gets fixed. Has anyone found a workaround for this in the meantime?

edit: the wsdl location is: https://test.efsllc.com/richapp/Wsdl.action?wsdl=/axis2/services/CardManagementWS

RKDMax avatar Jun 11 '19 12:06 RKDMax

@RKDMax Did you ever figure out a workaround for this? I'm attempting to use the same API with the same errors.

joeytitans avatar Aug 20 '19 13:08 joeytitans

@RKDMax Did you ever figure out a workaround for this? I'm attempting to use the same API with the same errors.

@joeytitans Unfortunately not. I had to make a separate .Net Framework project and consume the webservice the old way. My intent was that I could then take the results of those webservice calls and re-serve them up as my own Web API results which I could then consume in my .Net Core project.

RKDMax avatar Aug 20 '19 13:08 RKDMax

I get the exactly same exception (as in the initial post) when trying to consume any endpoint from this WSDL: https://api.webdispecink.cz/code/WebDispecinkServiceNet.php?wsdl

janpalas2 avatar Oct 02 '19 12:10 janpalas2

The issue is with the System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=X)] on the properties of the Request/Resonse classes. If you remove Namespace="" from the attribute, it resolves the issue.

dcomartin avatar Nov 12 '19 21:11 dcomartin

The issue is with the System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=X)] on the properties of the Request/Resonse classes. If you remove Namespace="" from the attribute, it resolves the issue.

I've removed the Namespace="" as you recommended and it worked for me. I was able to login, but then I was not able to call some of the actions receiving 'org.apache.axis2.databinding.ADBException: Unexpected subelement clientId' error.

dianakk avatar Jul 09 '20 05:07 dianakk

I am using the same wsdl https://test.efsllc.com/richapp/Wsdl.action?wsdl=/axis2/services/CardManagementWS in Visual Studio 2017, .Net version 4.6.1 in a .Net Web Application and I still receive the same error related to Namespace="". Removing Namespace="" from generated cs file allowed me to login the service and call some of the methods, but the most important ones returned with error 'org.apache.axis2.databinding.ADBException: Unexpected subelement clientId'

Here is my code CardManagementEPClient client = new CardManagementEPClient(); client.Endpoint.Address = new EndpointAddress(""); var binding = new BasicHttpsBinding(); client.Endpoint.Binding = binding ;

string clientId = client.login("", ""); var res = client.getTransExtLoc(clientId, DateTime.Now.AddDays(-10), DateTime.Now); client.logoutAsync(clientId);

Has anyone already overcome this problem? Please, share your solution.

dianakk avatar Jul 09 '20 06:07 dianakk

@RKDMax Did you ever figure out a workaround for this? I'm attempting to use the same API with the same errors.

@joeytitans Unfortunately not. I had to make a separate .Net Framework project and consume the webservice the old way. My intent was that I could then take the results of those webservice calls and re-serve them up as my own Web API results which I could then consume in my .Net Core project.

Could you please clarify what do you mean by ".Net Framework project" and if possible the "old way" of service consumption you mentioned in your post. I am using .Net Framework web application wit .Net 4.6.1 in VS 2017 and get the same error as you.

Thank you in advance

dianakk avatar Jul 09 '20 06:07 dianakk

@RKDMax Did you ever figure out a workaround for this? I'm attempting to use the same API with the same errors.

@joeytitans Unfortunately not. I had to make a separate .Net Framework project and consume the webservice the old way. My intent was that I could then take the results of those webservice calls and re-serve them up as my own Web API results which I could then consume in my .Net Core project.

Could you please clarify what do you mean by ".Net Framework project" and if possible the "old way" of service consumption you mentioned in your post. I am using .Net Framework web application wit .Net 4.6.1 in VS 2017 and get the same error as you.

Thank you in advance

@dianakk - Make sure you add the webservice as a "Web Reference" and not a "Connected Service". In VS 2017, go to the Solution Explorer, right-click References, then "Add Service Reference". In the "Add Service Reference" modal window, copy paste the EFS WSDL url into the Address bar and click the "Go" button to find the webservice.

RKDMax avatar Jul 10 '20 15:07 RKDMax

@RKDMax thank you very much for your quick and helpful response. I created a Web Request using WSDL and it worked successfully. 👍

dianakk avatar Jul 10 '20 17:07 dianakk

I had the same problem with There was an error reflecting 'login' only in a unix (Docker and wsl2) environment. On Windows there was no problem at all.

I tried to create the connected service via the dotnet-svcutil (version 2.0.1), but this didn't solve the issue.

I finally managed to find the root the my problem. I published my application with the following dotnet command: dotnet publish "myapp/myapp.csproj" -c Release -r linux-x64 --self-contained true -p:PublishTrimmed=true -p:ReadyToRun=true -p:ReadyToRunShowWarnings=true -o publish

When I removed the attribute -p:PublishTrimmed=true it finally worked both under wsl2 and in my docker environment.

rogatec avatar Oct 05 '20 14:10 rogatec

@rogatec, are you using .NET 5? If so, which release are you using? There's been some bug fixes around trimming and DCS recently and I don't know if this is a new problem or and already fixed one.

mconnew avatar Oct 06 '20 05:10 mconnew

@mconnew no I am using .net core 3.1.402 / Host 3.1.8.

rogatec avatar Oct 06 '20 06:10 rogatec

@rogatec - it sounds like you are running into a linker issue. Can you open an new issue for this scenario at https://github.com/mono/linker/issues/new?

It would be great if you had full repro steps describing how you got the issue. If possible, could you link to a project that you already have that shows the problem when you publish it? That would be the easiest for the linker team to investigate the problem.

eerhardt avatar Oct 06 '20 17:10 eerhardt

Has anyone solved this problem?

mspaic96 avatar Jul 19 '21 07:07 mspaic96

This issue still exists.

By the way, I tried a workaround with .net framework 4.7.2 and 4.8, and it didn't help. I use VS2022. @RKDMax did you ever try it with VS2022 and one of these .net frameworks?

selvinfehric avatar Oct 28 '22 20:10 selvinfehric