0

I'm setting up a new WCF service on a new server I got, but when I try to access the service through a xamarin application I get the following error

"Error in deserializing body of request message for operation 'GetString'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetString' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetStringAsync' and namespace 'http://tempuri.org/'"

I have used the method of creating a proxy (with a class library and connected service) for creating the client to be used in my xamarin application. I have used this exact method before without any problems, but now I can't seem to get this to work.

I have tried googling this, but the only similar errors I could find were where the methods name were the same, but the namespace as mentioned above was different which does not apply in my specific error. I have recreated the project, and redeployed a few times without any success.

IService

    [ServiceContract]
    public interface IPM_Service
    {
        [OperationContract]
        List<dbUsersModel> GetUsers();

        [OperationContract]
        int InsertUser(dbUsersModel user, int userid);

        [OperationContract]
        string GetString(string test);
    }

IService Implementation

    public class PM_Service : IPM_Service
    {
        xamPropertyManagementEntities Entity = new xamPropertyManagementEntities();

        public List<dbUsersModel> GetUsers()
        {
            var data = Entity.SP_SELECT_USERS().ToList();
            List<dbUsersModel> users = new List<dbUsersModel>();

            foreach (var item in data)
            {
                users.Add(new dbUsersModel() { dbUserID = item.USR_ID, dbUserName = item.USR_NAME, dbUserSurname = item.USR_SURNAME, dbUserUsername = item.USR_USERNAME, dbUserPassword = item.USR_PASSWORD, dbUserIDNo = item.USR_IDNO, dbUserContactNo = item.USR_CONTACTNO, dbUserEmail = item.USR_EMAIL, dbUserAddress1 = item.USR_ADDRESS1, dbUserAddress2 = item.USR_ADDRESS2, dbUserAddress3 = item.USR_ADDRESS3, dbUserAddress4 = item.USR_ADDRESS4 });
            }

            return users;
        }

        public int InsertUser(dbUsersModel user, int userid)
        {
            var insert = Entity.SP_INSERT_USER(user.dbUserUsername, user.dbUserPassword, user.dbUserName, user.dbUserSurname, user.dbUserIDNo, user.dbUserContactNo, user.dbUserEmail, user.dbUserAddress1, user.dbUserAddress2, user.dbUserAddress3, user.dbUserAddress4, userid);

            decimal? returnID = insert.SingleOrDefault().Value;

            int id = (int)returnID.DefaultIfEmpty(0);

            return id;
        }

        public string GetString(string test)
        {
            return test;
        }
    }

    public class dbUsersModel
    {
        public int dbUserID { get; set; }

        public string dbUserUsername { get; set; }
        public string dbUserPassword { get; set; }

        public string dbUserName { get; set; }
        public string dbUserSurname { get; set; }
        public string dbUserIDNo { get; set; }

        public string dbUserContactNo { get; set; }
        public string dbUserEmail { get; set; }
        public string dbUserAddress1 { get; set; }
        public string dbUserAddress2 { get; set; }
        public string dbUserAddress3 { get; set; }
        public string dbUserAddress4 { get; set; }
    }

Proxy Code

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     //
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PMProxy
{
    using System.Runtime.Serialization;


    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
    [System.Runtime.Serialization.DataContractAttribute(Name="dbUsersModel", Namespace="http://schemas.datacontract.org/2004/07/PM_Service")]
    public partial class dbUsersModel : object
    {

        private string dbUserAddress1Field;

        private string dbUserAddress2Field;

        private string dbUserAddress3Field;

        private string dbUserAddress4Field;

        private string dbUserContactNoField;

        private string dbUserEmailField;

        private int dbUserIDField;

        private string dbUserIDNoField;

        private string dbUserNameField;

        private string dbUserPasswordField;

        private string dbUserSurnameField;

        private string dbUserUsernameField;

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserAddress1
        {
            get
            {
                return this.dbUserAddress1Field;
            }
            set
            {
                this.dbUserAddress1Field = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserAddress2
        {
            get
            {
                return this.dbUserAddress2Field;
            }
            set
            {
                this.dbUserAddress2Field = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserAddress3
        {
            get
            {
                return this.dbUserAddress3Field;
            }
            set
            {
                this.dbUserAddress3Field = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserAddress4
        {
            get
            {
                return this.dbUserAddress4Field;
            }
            set
            {
                this.dbUserAddress4Field = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserContactNo
        {
            get
            {
                return this.dbUserContactNoField;
            }
            set
            {
                this.dbUserContactNoField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserEmail
        {
            get
            {
                return this.dbUserEmailField;
            }
            set
            {
                this.dbUserEmailField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public int dbUserID
        {
            get
            {
                return this.dbUserIDField;
            }
            set
            {
                this.dbUserIDField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserIDNo
        {
            get
            {
                return this.dbUserIDNoField;
            }
            set
            {
                this.dbUserIDNoField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserName
        {
            get
            {
                return this.dbUserNameField;
            }
            set
            {
                this.dbUserNameField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserPassword
        {
            get
            {
                return this.dbUserPasswordField;
            }
            set
            {
                this.dbUserPasswordField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserSurname
        {
            get
            {
                return this.dbUserSurnameField;
            }
            set
            {
                this.dbUserSurnameField = value;
            }
        }

        [System.Runtime.Serialization.DataMemberAttribute()]
        public string dbUserUsername
        {
            get
            {
                return this.dbUserUsernameField;
            }
            set
            {
                this.dbUserUsernameField = value;
            }
        }
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="PMProxy.IPM_Service")]
    public interface IPM_Service
    {

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IPM_Service/GetUsers", ReplyAction="http://tempuri.org/IPM_Service/GetUsersResponse")]
        System.Threading.Tasks.Task<PMProxy.dbUsersModel[]> GetUsersAsync();

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IPM_Service/InsertUser", ReplyAction="http://tempuri.org/IPM_Service/InsertUserResponse")]
        System.Threading.Tasks.Task<int> InsertUserAsync(PMProxy.dbUsersModel user, int userid);

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IPM_Service/GetString", ReplyAction="http://tempuri.org/IPM_Service/GetStringResponse")]
        System.Threading.Tasks.Task<string> GetStringAsync(string test);
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
    public interface IPM_ServiceChannel : PMProxy.IPM_Service, System.ServiceModel.IClientChannel
    {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
    public partial class PM_ServiceClient : System.ServiceModel.ClientBase<PMProxy.IPM_Service>, PMProxy.IPM_Service
    {

    /// <summary>
    /// Implement this partial method to configure the service endpoint.
    /// </summary>
    /// <param name="serviceEndpoint">The endpoint to configure</param>
    /// <param name="clientCredentials">The client credentials</param>
    static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);

        public PM_ServiceClient() : 
                base(PM_ServiceClient.GetDefaultBinding(), PM_ServiceClient.GetDefaultEndpointAddress())
        {
            this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IPM_Service.ToString();
            ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
        }

        public PM_ServiceClient(EndpointConfiguration endpointConfiguration) : 
                base(PM_ServiceClient.GetBindingForEndpoint(endpointConfiguration), PM_ServiceClient.GetEndpointAddress(endpointConfiguration))
        {
            this.Endpoint.Name = endpointConfiguration.ToString();
            ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
        }

        public PM_ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : 
                base(PM_ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
        {
            this.Endpoint.Name = endpointConfiguration.ToString();
            ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
        }

        public PM_ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(PM_ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
        {
            this.Endpoint.Name = endpointConfiguration.ToString();
            ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
        }

        public PM_ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress)
        {
        }

        public System.Threading.Tasks.Task<PMProxy.dbUsersModel[]> GetUsersAsync()
        {
            return base.Channel.GetUsersAsync();
        }

        public System.Threading.Tasks.Task<int> InsertUserAsync(PMProxy.dbUsersModel user, int userid)
        {
            return base.Channel.InsertUserAsync(user, userid);
        }

        public System.Threading.Tasks.Task<string> GetStringAsync(string test)
        {
            return base.Channel.GetStringAsync(test);
        }

        public virtual System.Threading.Tasks.Task OpenAsync()
        {
            return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
        }

        public virtual System.Threading.Tasks.Task CloseAsync()
        {
            return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
        }

        private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
        {
            if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IPM_Service))
            {
                System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
                result.MaxBufferSize = int.MaxValue;
                result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
                result.MaxReceivedMessageSize = int.MaxValue;
                result.AllowCookies = true;
                return result;
            }
            throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
        }

        private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
        {
            if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IPM_Service))
            {
                return new System.ServiceModel.EndpointAddress("http://localhost:8733/Design_Time_Addresses/PM_Service/PM_Service/");
            }
            throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
        }

        private static System.ServiceModel.Channels.Binding GetDefaultBinding()
        {
            return PM_ServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IPM_Service);
        }

        private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
        {
            return PM_ServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IPM_Service);
        }

        public enum EndpointConfiguration
        {

            BasicHttpBinding_IPM_Service,
        }
    }
}

The only thing that I can possibly think of, is that my IIS may not be set up correctly, since this is the first time I have had to set up IIS by myself. The server is a VPS running Windows Server 2016. I may very well be wrong about the cause, and it may be something I have missed in the config of the service itself, or the proxy client I created.

Any ideas that might be able to help?

TH3SN3R
  • 47
  • 9
  • You get this error on the server side? Can you post the client proxy code as well? I suppose you call a method `GetStringAsync` from your client code with an operationcontract without a `Name` property. – Jesse de Wit Jul 22 '19 at 13:14
  • Yes I get this error as response to my request from the application. I will post the proxy code now – TH3SN3R Jul 22 '19 at 13:15
  • Not exactly helpful, but your issue is registered [here](https://github.com/dotnet/wcf/issues/2463). Looks like Xamarin does not fully support the WCF stack. – Jesse de Wit Jul 22 '19 at 13:30
  • I have come across that same post in my google searches, its the same error but because of a different cause. That error was caused by inconsistent namespaces. The first time I ever worked on WCF was setting it up for a xamarin app last year, and I did the exact same thing again start of this year, both of the times everything went quite smoothly. This is what leads me to believe it may be something on my server set up incorrectly. – TH3SN3R Jul 22 '19 at 13:34
  • Your client sends xml with a root node of 'GetStringAsync', based on that proxy. I believe a 'normal' .Net framework WCF client would wrap that in a 'GetString' node. – Jesse de Wit Jul 22 '19 at 13:38
  • The link posted by Jesse explicitly talks about Async not working with Xamarin because of how `svcutil` generates the code and provides a workaround in one of the comments - https://github.com/dotnet/wcf/issues/2463#issuecomment-385044805 - thinking that might be the exact same issue you're having? – Marius Bughiu Jul 22 '19 at 13:38
  • 1
    After reading through the entire comment thread and some testing on my side, it seems you guys are correct. The proxy implementation of WCF does not work properly with xamarin (android and ios projects) it seems. Although the UWP versions seem to work just fine somehow. I will give some of the workarounds mentioned a try, else I'm just going to have to implement the eventhandlers for on complete events from the service side. Thanks anyway guys, I appreciate the help – TH3SN3R Jul 22 '19 at 14:05
  • Use the workaround highlighted here: https://stackoverflow.com/questions/10054581/monotouch-wcf-how-to-consume-the-wcf-service-without-svcutil/10056431#10056431 I've seen this exact issue before – JKennedy Jul 22 '19 at 15:28

0 Answers0