0

The application is sending several requests to different endpoints and all works well in .NET Framework but when ported to Core one of the services response has not all the data, only parts of it with and with no error.

I have tried some refractoring of the code and been looking if there is a async/sync problem but I dont really know where to look. I am hoping that for an experienced programmer the problem will show in the code that follows. If not, please let me know and Ill provide a complete project.

CONTRACT, first .NET Framework, second .NET Core

public class InskrivningDirekt
  {
    public IEnumerable<InskrivningMemberType> GetInskrivningData(string 
    objektid)
    {
      InskrivningPortTypeClient client = new InskrivningPortTypeClient();
      client.ClientCredentials.UserName.UserName = "";
      client.ClientCredentials.UserName.Password = "";

      InskrivningRegisterenhetFilterType filter = new 
      InskrivningRegisterenhetFilterType();
      filter.ItemsElementName = new ItemsChoiceType[] { 
      ItemsChoiceType.objektidentitet };
      filter.Items = new string[] { objektid };

      GetInskrivningRequestType request = new GetInskrivningRequestType()
      {
        IncludeData = new InskrivningDatasetType()
        {
          Items = new bool[] { true },
          ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.total }
        },
        Items = new object[] { filter }
      };

      return client.GetInskrivning(request).InskrivningMember;
    }
  }
public class InskrivningDirekt
  {
    public IEnumerable<InskrivningMemberType> GetInskrivningData(string 
    objektid)
    {
      InskrivningPortTypeClient client = new InskrivningPortTypeClient();
      client.ClientCredentials.UserName.UserName = Creds.UserName;
      client.ClientCredentials.UserName.Password = Creds.Password;

      using (OperationContextScope scope = new 
      OperationContextScope(client.InnerChannel))
      {
        HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
        httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + 
          Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + ":" + 
          client.ClientCredentials.UserName.Password));
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

        InskrivningRegisterenhetFilterType filter = new InskrivningRegisterenhetFilterType();
        filter.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.objektidentitet };
        filter.Items = new string[] { objektid };

        GetInskrivningRequestType request = new GetInskrivningRequestType()
        {
          IncludeData = new InskrivningDatasetType()
          {
            Items = new bool[] { true },
            ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.total }
          },
          Items = new object[] { filter }
        };

        return client.GetInskrivning(request).InskrivningMember;
      }
    }
  }

CONTROLLER, only the one with an issue

private PropertyInfo GetData(string objektid, string[] categories)
        {
            PropertyInfo data = new PropertyInfo();
            List<Task> tasks = new List<Task>();

            tasks.Add(Task.Factory.StartNew(() =>
            {
                data.Inskrivningsinformation = LMDirectDataModel.GetEnlistmentData(objektid);
            }));

            Task.Factory.ContinueWhenAll(tasks.ToArray(), results => { }).Wait();
            return data;
        }

.NET Core response

.NET Framework response

Examples of the differences in generated reference

Generated with Visual Studio 2017 ASP.NET Framework ?

[System.Xml.Serialization.XmlArrayAttribute(Order = 9)]        
        [System.Xml.Serialization.XmlArrayItemAttribute("Lagfart", typeof(LagfartType))]
        [System.Xml.Serialization.XmlArrayItemAttribute("Tomtrattsinnehav", typeof(TomtrattsinnehavType))]
        [System.Xml.Serialization.XmlArrayItemAttribute("InskrivetAgande", IsNullable = false)]
        public InskrivetAgandeType[] Agande
        {
            get
            {
                return this.agandeField;
            }
            set
            {
                this.agandeField = value;
                this.RaisePropertyChanged("Agande");
            }
        } 

Generated with Visual Studio 2019 Preview ASP.NET Core 3.0

    [System.Xml.Serialization.XmlArrayAttribute(Order = 9)]
    [System.Xml.Serialization.XmlArrayItemAttribute("InskrivetAgande", IsNullable = false)]
    public InskrivetAgandeType[] Agande
    {
      get
      {
        return this.agandeField;
      }
      set
      {
        this.agandeField = value;
      }
    } 
Sveed
  • 13
  • 5
  • Is your error related to Authentication? – Paul Lorica Sep 03 '19 at 17:44
  • No, I was thinking the same but in that case the would be an error and no response at all. Now it is only parts of the response that is missing. I added images of the two different responses – Sveed Sep 03 '19 at 17:54
  • Any chance you are just pointing to a different service or connection string? – Paul Lorica Sep 03 '19 at 17:56
  • The both requests are pointing to the same same service. Note: When connecting with WCF to the WSDL endpoint I had to use Visual Studio 2019 preview and the new(?) option to generate synnchronous operation. – Sveed Sep 03 '19 at 18:03
  • 1
    **Progress:** The problem has to do with the generation of the service Reference.cs by the .Net Core WCF tool. So I copy/pasted some classes generated in .NET Framework to Core. This fixed the request testobjects but I still have not a clue what else is missing in this and the other service References so this is not solved. – Sveed Sep 04 '19 at 09:46
  • Are you using Add > ConnectedService? – Paul Lorica Sep 04 '19 at 21:44
  • Yes, I have also tried to generate with svcUtil on the .xsd file with the same result. I added example of what the two enviroment produce when using "Add service reference" and WCF Web Service Reference Provider (Core) – Sveed Sep 05 '19 at 04:57
  • Since it's the same service, why did you add additional basic credentials to the request in the second (Core) call, but not in the first call in the .NET framework? What is the binding type on the server and what authentication type is used? Also, for complex data types, I recommend you use the DataContract attribute. If you nest other object service types, use Knowntype attribute, I suspect an error may have occurred during the serialization process. – Abraham Qian Sep 05 '19 at 06:33
  • https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts?view=netframework-4.8 https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-contract-known-types?view=netframework-4.8 – Abraham Qian Sep 05 '19 at 06:34
  • Hi @AbrahamQian The auth type is Basic and thats why I added the headers in the Core call. Without it I get an "...unauthorized with... scheme Anonymous" in Core. Could you expound "...binding type on the server"? Thanks for the tips, I will refactor this when I get this solved. You are right, the serialization is not working correctly. – Sveed Sep 05 '19 at 09:18
  • Got a tip that I am looking into but I guess this dont solves the issue either. https://stackoverflow.com/questions/15819740/net-auto-generated-wsdl-client-does-not-handle-abstract-type-when-maxoccurs-att – Sveed Sep 05 '19 at 09:19
  • the binding type in WCF on the server-side determined the type of service channel. There might be something wrong with the process of porting the service to Core since Core does not well compatible with WCF. What is the default serializer? Have you tried to use DataContract attribute? – Abraham Qian Sep 06 '19 at 06:36
  • @AbrahamQian Binding: ` ` To answer the question about default serialization I use this reference _"Windows Communication Foundation (WCF) uses the DataContractSerializer as its default serialization engine..."_. I am reading up on the DataContract Attribute but not sure how to implement it. – Sveed Sep 07 '19 at 08:53

0 Answers0