wcf icon indicating copy to clipboard operation
wcf copied to clipboard

InvalidOperationException: There was an error reflecting 'ticket'.

Open elmojo opened this issue 8 years ago • 19 comments

This is from the WSDL from before but hand corrected to fix errors that the SvcUtil was reporting during proxy creation.

I am now getting an error when trying to use the service, namely the loginAsync method. I get the following errors:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Test.Service.UnitTest1.TestMethod2() in C:\Source\Service\Test.Service\UnitTest1.cs:line 57

Inner Exception 1:
InvalidOperationException: There was an error reflecting 'ticket'.

Inner Exception 2:
InvalidOperationException: There was an error reflecting type 'Service.SoapReference.Authentication.AuthenticationTicket'.

Inner Exception 3:
NullReferenceException: Object reference not set to an instance of an object.

AuthenticationService.wsdl.txt

elmojo avatar Aug 30 '18 21:08 elmojo

Is anyone looking into this issue?

elmojo avatar Sep 04 '18 20:09 elmojo

@elmojo Can you share the exception call stack? In the meantime, we will try to setup a repro.

Lxiamail avatar Sep 05 '18 21:09 Lxiamail

Exception Stack Trace:
at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access)
at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel)
at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc)
at System.ServiceModel.Description.XmlSerializerOperationBehavior.Reflector.XmlSerializerImporter.ImportMembersMapping(XmlName elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, 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.Reflector.OperationReflector.get_Request()
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.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime)
at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters)
at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint, Boolean useActiveAutoClose)
at System.ServiceModel.ChannelFactory.CreateFactory()
at System.ServiceModel.ChannelFactory.OnOpening()
at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan timeout)
at System.Runtime.TaskHelpers.WaitForCompletion(Task task)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at System.ServiceModel.ChannelFactory.EnsureOpened()
at System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
at System.ServiceModel.ChannelFactory`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannel()
at System.ServiceModel.ClientBase`1.CreateChannelInternal()
at System.ServiceModel.ClientBase`1.get_Channel()
at BOne.Service.SoapReference.Authentication.AuthenticationServiceClient.loginAsync(String user, String password) in C:\Source\BOne-Service\Service\SoapReference\Authentication.cs:line 371
at BOne.Service.BOneService.Login() in C:\Source\BOne-Service\Service\BOneService.cs:line 32
at BOne.Service.BOneService.GetTicket() in C:\Source\BOne-Service\Service\BOneService.cs:line 95
at BOne.Service.BOneService.EquityAttributionResults(String quasarCode, DateTime calculationDate, Int32 level, Period period, PortfolioConfiguration portfolioConfig, Boolean enableSearchDate, Boolean viewSecurities) in C:\Source\BOne-Service\Service\BOneService.cs:line 42
	
	Inner Exception Stack Trace:
	at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)
	at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
	at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
	at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter)
		
		Inner Exception Stack Trace:
		at Microsoft.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)
		at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)
		at Microsoft.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)

elmojo avatar Sep 05 '18 22:09 elmojo

Any update, status, workaround for this? This is going to quickly become a blocker for us.

elmojo avatar Sep 11 '18 14:09 elmojo

@elmojo Looks like we don't have access to the endpoint, we got the System.ServiceModel.EndpointNotFoundException exception. If it is okay, can you share the WCF server contacts, which repro the problem? And what change you had made to the original WSDL file to make svcutil tool happy?

Lxiamail avatar Sep 11 '18 17:09 Lxiamail

Yes the service/endpoint is internal.

I originally was having issues with the SvcUtil even creating the proxy methods. It would give errors and generate an empty client. See this posted issue near the end.

I was able to get the SvcUtil working by hand modifying the WSDL and using that WSDL instead as the input for the SvcUtil. I had to hand modify the WSDL because the service and thus WSDL are from a 3rd party vendor. I've notified them of the changes needed but I'm not sure what their course of action is.

Here are the manual changes I made to the WSDL:

AuthenticationService WSDL Changes:
ADD (After each complexType declaration):
<element type="impl:WSAuthenticationException" name="WSAuthenticationException" />

FROM:
<wsdl:message name="WSAuthenticationException">
<wsdl:part name="fault" type="impl:WSAuthenticationException" /> 
</wsdl:message>
TO:
<wsdl:message name="WSAuthenticationException">
<wsdl:part name="fault" element="impl:WSAuthenticationException" /> 
</wsdl:message>

I am not sure about what you mean "WCF contacts".

My assumption would have been that you could take the WSDL provided and use SvcUtil to generate the proxy client. From there you could mock the service to provide the expected XML based upon the WSDL. I am getting the error on the login service. When SvcUtil generated proxy client receives the response from the service, it is throwing the error on the code where the XML gets mapped to the SvcUtil generated model object.

I'll provide a sample of the login service output.

elmojo avatar Sep 11 '18 17:09 elmojo

Here is a sample output from the login service. It was produced through SoapUI, which was able to process the original WSDL and the modified WSDL.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:loginResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:xml-soap-bisam">
         <loginReturn xsi:type="ns1:AuthenticationTicket">
            <expirationDate xsi:type="xsd:dateTime">2018-09-12T05:58:31.289Z</expirationDate>
            <expirationDateTime xsi:type="xsd:dateTime">2018-09-12T05:58:31.289Z</expirationDateTime>
            <extId xsi:type="soapenc:int" xsi:nil="true" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <issueDate xsi:type="xsd:dateTime">2018-09-11T17:58:31.289Z</issueDate>
            <issueDateTime xsi:type="xsd:dateTime">2018-09-11T17:58:31.289Z</issueDateTime>
            <serverUrl xsi:type="soapenc:string" xsi:nil="true" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
            <sessionId xsi:type="soapenc:long" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">999962320</sessionId>
            <token xsi:type="xsd:int">-856099999</token>
         </loginReturn>
      </ns1:loginResponse>
   </soapenv:Body>
</soapenv:Envelope>

So my problem is the code generated by the SvcUtil cannot translate the above XML into the model object it created based upon the WSDL.

elmojo avatar Sep 11 '18 18:09 elmojo

@mlacouture Can you look into why SvcUtil tool doesn't work with the original WSDL file?

Lxiamail avatar Sep 11 '18 18:09 Lxiamail

Hi @elmojo If you are able to share the full wsdl we can reopen issue #2591 and continue investigating. thanks,

mlacouture avatar Sep 11 '18 21:09 mlacouture

Yes, it is the second one I attached to #2591. But here it is again. b-one-authentication.wsdl.txt

elmojo avatar Sep 11 '18 21:09 elmojo

I made the changes noted above to be able to get the SvcUtil to produce a usable proxy client.

elmojo avatar Sep 11 '18 21:09 elmojo

Looks like this was resolved in #2591

StephenBonikowsky avatar Oct 29 '18 18:10 StephenBonikowsky

@StephenBonikowsky

I don't believe so. Also this issue and #2591 are not related. This one deals with failure to deserialize data wrapped within a SOAP envelope. #2591 is related to the SvcUtil generating an empty client from a valid WSDL.

elmojo avatar Oct 29 '18 19:10 elmojo

@elmojo My apologies I see now how the conversation forked.

StephenBonikowsky avatar Oct 29 '18 19:10 StephenBonikowsky

There's a couple of things I noticed about this issue. We shouldn't need access to any endpoint as the exception in the provided callstack is happening when ChannelFactory.Open() is getting implicitly called when calling ChannelFactory.CreateChannel(). There's no request in flight when the exception happens. If we're getting an EndpointNotFoundException, then we haven't reprod the problem.
The second thing is that there's a call to **Microsoft.Xml.Serialization.**XmlReflectionImporter.ImportMembersMapping. I'm struggling to find where that class is coming from. Any generated code should have a namespace of Microsoft.Xml.Serialization.GeneratedAssembly. This might just be I'm missing something, but I'm struggling to see where that code lives.
@elmojo, can you verify which version of .NET Core you are using?

mconnew avatar Nov 01 '18 22:11 mconnew

@mconnew .NET Core 2.1

elmojo avatar Nov 01 '18 23:11 elmojo

Having same issue at factory.CreateChannel(); Version .NET core 2.1 Attached the exception trace log Errorlog.txt

venkatdev22 avatar Dec 10 '18 11:12 venkatdev22

Having similar issue System.InvalidOperationException HResult=0x80131509 Message=There was an error reflecting 'return'. Source=System.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.Open(TimeSpan timeout) at System.ServiceModel.ChannelFactory.EnsureOpened() at System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ClientBase1.CreateChannel() at System.ServiceModel.ClientBase1.CreateChannelInternal() at System.ServiceModel.ClientBase1.get_Channel() at IMobileCommService.MobileCommClient.IMobileCommService.IMobileComm.GetWaitingEventsAsync(GetWaitingEventsRequest request) in C:\REPOS\TruckMate\Code\Server\TruckMateIntegrationAdapter\Connected Services\IMobileCommService\IMobileCommServiceReference.cs:line 14612 This exception was originally thrown at this call stack: System.Xml.Serialization.XmlReflectionImporter.ReconcileAccessor(System.Xml.Serialization.Accessor, System.Xml.Serialization.NameTable) System.Xml.Serialization.XmlReflectionImporter.ReconcileLocalAccessor(System.Xml.Serialization.ElementAccessor, string) System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(System.Xml.Serialization.MemberMapping, System.Xml.Serialization.FieldModel, System.Xml.Serialization.XmlAttributes, string, System.Type, bool, bool, System.Xml.Serialization.RecursionLimiter) System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(System.Xml.Serialization.XmlReflectionMember, string, System.Xml.Serialization.XmlReflectionMember[], bool, bool, System.Xml.Serialization.RecursionLimiter) System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(System.Xml.Serialization.XmlReflectionMember[], string, bool, bool, bool, System.Xml.Serialization.RecursionLimiter) Inner Exception 1: InvalidOperationException: The top XML element 'return' from namespace '' references distinct types System.String and IMobileCommService.TContact[]. Use XML attributes to specify another XML name or namespace for the element or types.

cbukenya avatar Jan 21 '20 09:01 cbukenya

Is this related to #2472? Any news on this?

selvinfehric avatar Oct 31 '22 14:10 selvinfehric