locked
Method cannot be reflected.There was an error reflecting type 'string'

    General discussion

  • Hi everybody, I am trying to consume a webservice generated in Jaxws.Now when i generate a proxy for the wsdl using dotnet iDE and then when i try to instatiate the generated proxy class.I get the method cannot be reflcted and the inner exception is something like this

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    System.InvalidOperationException: There was an error reflecting 'string2'. ---> System.InvalidOperationException: There was an error reflecting type 'DisplayResult.HelloService.string2'. ---> System.InvalidOperationException: Types 'DisplayResult.HelloService.string2' and 'DisplayResult.HelloService.string' both use the XML type name, 'string', from namespace 'http://www.w3.org/2001/XMLSchema'. Use XML attributes to specify a unique XML name and/or namespace for the type.

       at System.Xml.Serialization.XmlReflectionImporter.GetTypeMapping(String typeName, String ns, TypeDesc typeDesc, NameTable typeLib, Type type)

       at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)

       at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)

       --- End of inner exception stack trace ---

       at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)

       at System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter)

       at System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel, RecursionLimiter limiter)

       at System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter)

       --- End of inner exception stack trace ---

       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.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, Boolean serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse use, SoapParameterStyle paramStyle, String elementName, String elementNamespace, Boolean nsIsDefault, XmlReflectionMember[] members, Boolean validate, Boolean openModel, String key, Boolean writeAccess)

       at System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs)---

    ----------------------------------------------------------------------------------------------------------------------------------------

    I have tried to instatiate by manually editing the proxy class and removing the Typename='string' attribute for one of my soapheaders.

    When the wsdl contains more than one primitive type.this problem is faced as the proxy generator puts the Typename attribute only after teh first occurencs of the primitive types eg string or integer.

     

    The proxy generated for string is as follows

     

    /// <remarks/>

    [System.CodeDom.Compiler.

    GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]

    [System.

    SerializableAttribute()]

    [System.Diagnostics.

    DebuggerStepThroughAttribute()]

    [System.ComponentModel.

    DesignerCategoryAttribute("code")]

    [System.Xml.Serialization.

    XmlTypeAttribute(TypeName="string", Namespace="http://www.w3.org/2001/XMLSchema")]

    [System.Xml.Serialization.

    XmlRootAttribute("Memo", Namespace="http://xmlns.fmr.com/systems/dev/xtrac/2004/06/", IsNullable=true)]

     

    public partial class string2 : System.Web.Services.Protocols.SoapHeader {

     

     

    private string[] textField;

     

     

    /// <remarks/>

    [System.Xml.Serialization.

    XmlTextAttribute()]

     

    public string[] Text {

     

    get {

     

    return this.textField;

    }

     

    set {

     

    this.textField = value;

    }

    }

    }

     

    Where string2 is the variable type for a primitive string soap header.

    WHen i manually remove the typename attribute it is working fine.

    Is there any way i can get rid of this or is this a bug in wsdl generator of dotnet.

    Wednesday, March 09, 2011 9:38 AM

All replies

  • Unless you're stuck using .NET 2.0, you should try using "Add Service Reference" to see if it does any better.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Wednesday, March 09, 2011 7:50 PM
  • Yes John, Due to my current proj architecture.I cannot afford to use WCF anc change the entire proj framework.its a huge effort.

    I am consuming java Jaxws webservices which uses dynamic wsdl and hence the problem.

    I can go ahead with manual editing of my reference.cs for one of my soapheaders which has the

    XmlTypeAttribute(TypeName="string", Namespace=http://www.w3.org/2001/XMLSchema)]

    When i remove the TypeName='string' from the above.I am able to instantiate the proxy class.I no longer get the "method cannot be reflected error".

    But I feel there is something strange abt the wsdl.exe erractic behavior.

    Thanks for you help.

    Ramesh.S

    Thursday, March 10, 2011 4:54 AM
  • Using "Add Service Reference" would not require any change to your architecture. Why do you think it would?
    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Thursday, March 10, 2011 7:02 PM