wcfmauivisual-studio-2022webservice-clientsoap1.2

Error WCF service CustomBinding endpointin Visual Studio .Net MAUI Soap 1.2


I have the following problem, I have a Visual Studio 17.9.6 .Net MAUI net 8.0, I have a .asmx web service that when connected by soap 1.2 in EndpointConfiguration in the GetBinding in the HttpsTransportBindingElement part I get the following error:

System.ArrayTypeMismatchException Attempted to access an element as a type incompatible with the array.

Here in the GetBindingForEndpoint:

if ((endpointConfiguration == EndpointConfiguration.srvNumbSoap12))
{
    System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
    System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
    textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
    result.Elements.Add(textBindingElement);
    System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
    httpsBindingElement.AllowCookies = true;
    httpsBindingElement.MaxBufferSize = int.MaxValue;
    httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
    -->result.Elements.Add(httpsBindingElement);
    return result;
}

When connecting the service I have it as System.Array collection type, Dictionary Collection type: System.Collections.Generic.Dictionary, on the next page I make it public with generate synchronous operations.

If I try it in older versions, for example in 17.8.6, you can do it without any problems.

Does it have anything to do with the version that has changed something?


Solution

  • This issue ArrayTypeMismatchException that arises inside Visual Studio 17.9.6 (.NET MAUI 8.0) links to alterations in the application of the CustomBinding. It is considered that Elements is being managed more so than older elements like 17.8.6.

    1. Verify Element Types:

    Make sure the types of the elements you specify when making amendments to the Elements collection To are correct. In the collection, make ensure that httpsBindingElement is a string of the expected type. If needed it might be useful to coerce it into the correct type.

    2. Use Specific Binding Element Collections:

    In place of directly extending the class with elements that usage needs, CustomBinding itself is extensible. As far as you are concerned, which, I would advise to use specific element binding catalogs which are in the System. ServiceModel namespace. For instance, when instantiating the textBindingElement, you are likely to find the utilisation of the TextMessageEncodingBindingElementCollection to be proper for the httpsBindingElement on the other hand, the HttpsTransportBindingElementCollection is more appropriate. It can be stated as evident that these collections offer type safety if the new elements are to be appended.


    Additional Tips: