I have a c# User model which is synced with the Azure Mobile services.
The definition of the User class is as follows:
public class Users : INotifyPropertyChanged
{
[JsonProperty("Id")]
private string id;
[JsonIgnore]
public string Id
{
get { return id; }
set { id = value; OnPropertyChanged("Id"); }
}
[JsonProperty("Name")]
private string name;
[JsonIgnore]
public string Name
{
get { return name; }
set { name = value; OnPropertyChanged("Name"); }
}
[JsonProperty("Email")]
private string email;
[JsonIgnore]
public string Email
{
get { return email; }
set { email = value; OnPropertyChanged("Email"); }
}
[JsonProperty("Password")]
private string password;
[JsonIgnore]
public string Password
{
get { return password; }
set { password = value; OnPropertyChanged("Password"); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if(propertyName != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
Now, in the XAML page code, once the user logs in, I try to get the user, like so:
var user = (await App.MobileService.GetTable<Users>().Where(u => u.Email == this.txtEmail.Text).ToListAsync()).FirstOrDefault();
If I remove the JsonProperty() and JsonIgnore() on private and public members, I get the error: NewtonSoft.Json Deserialization error.
In the above code, is there any simpler way other than declaring JsonProperty() and JsonIgnore on each private and public fields respectively?
I am calling web services and returning into list but I am not able to do same.
I want to bind drop down list with web services.
I have added INITIATORS_LIST class which contain all field which I want to bind in Drop down list like Companies, Countries, Divisions, Location... So on. How can I achieve any alternate method may I accept please ?
Sample JSON Data
{"Companies":[{"ACTIVE":true,"COMPANY_ID":1,"CompanyCode":"1000","CompanyName":"Almarai Company","CountryCode":"SAU","CountryName":"Saudi Arabia","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":6,"CompanyCode":"4000","CompanyName":"Almarai Co. Bahrain WLL","CountryCode":"BAH","CountryName":"Bahrain","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":8,"CompanyCode":"5000","CompanyName":"Bustan Al Khaleej Est.","CountryCode":"UAE","CountryName":"United Arab Emirates","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":11,"CompanyCode":"5200","CompanyName":"ALMARAI EMIRATES COMPANY L.L.C","CountryCode":"UAE","CountryName":"United Arab Emirates","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":15,"CompanyCode":"6000","CompanyName":"Al Kharafi Brothers","CountryCode":"KWT","CountryName":"Kuwait","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"ACTIVE":true,"COMPANY_ID":18,"CompanyCode":"7000","CompanyName":"Arabian Planets Company","CountryCode":"OMN","CountryName":"Oman","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"}],"Countries":[{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":1,"CountryCode":"SAU","CountryName":"Saudi Arabia","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":3,"CountryCode":"UAE","CountryName":"United Arab Emirates","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":4,"CountryCode":"BAH","CountryName":"Bahrain","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":5,"CountryCode":"OMN","CountryName":"Oman","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"},{"COUNTRY_ACTIVE":true,"COUNTRY_M_ID":7,"CountryCode":"KWT","CountryName":"Kuwait","DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales"}],"Divisions":[{"ACTIVE":true,"CompanyCode":null,"CompanyName":null,"CountryCode":null,"CountryName":null,"DB_CONNECTION_STRING":null,"DivisionCode":"1000","DivisionId":1,"DivisionName":"Sales","WEB_URL":null}],"Locations":
ALM_COUNTRY_M class:
public partial class ALM_COUNTRY_M : object, System.Runtime.Serialization.IExtensibleDataObject,
System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private bool COUNTRY_ACTIVEField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int COUNTRY_M_IDField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string CountryCodeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string CountryNameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string DivisionCodeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int DivisionIdField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string DivisionNameField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public bool COUNTRY_ACTIVE {
get {
return this.COUNTRY_ACTIVEField;
}
set {
if ((this.COUNTRY_ACTIVEField.Equals(value) != true)) {
this.COUNTRY_ACTIVEField = value;
this.RaisePropertyChanged("COUNTRY_ACTIVE");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int COUNTRY_M_ID {
get {
return this.COUNTRY_M_IDField;
}
set {
if ((this.COUNTRY_M_IDField.Equals(value) != true)) {
this.COUNTRY_M_IDField = value;
this.RaisePropertyChanged("COUNTRY_M_ID");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string CountryCode {
get {
return this.CountryCodeField;
}
set {
if ((object.ReferenceEquals(this.CountryCodeField, value) != true)) {
this.CountryCodeField = value;
this.RaisePropertyChanged("CountryCode");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string CountryName {
get {
return this.CountryNameField;
}
set {
if ((object.ReferenceEquals(this.CountryNameField, value) != true)) {
this.CountryNameField = value;
this.RaisePropertyChanged("CountryName");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string DivisionCode {
get {
return this.DivisionCodeField;
}
set {
if ((object.ReferenceEquals(this.DivisionCodeField, value) != true)) {
this.DivisionCodeField = value;
this.RaisePropertyChanged("DivisionCode");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int DivisionId {
get {
return this.DivisionIdField;
}
set {
if ((this.DivisionIdField.Equals(value) != true)) {
this.DivisionIdField = value;
this.RaisePropertyChanged("DivisionId");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string DivisionName {
get {
return this.DivisionNameField;
}
set {
if ((object.ReferenceEquals(this.DivisionNameField, value) != true)) {
this.DivisionNameField = value;
this.RaisePropertyChanged("DivisionName");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
INITIATORS_LIST Class:
public partial class INITIATORS_LIST : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] CompaniesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] CountriesField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] DivisionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.LOCATION[] LocationsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.REGION[] RegionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypesField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_COMPANY_M[] Companies {
get {
return this.CompaniesField;
}
set {
if ((object.ReferenceEquals(this.CompaniesField, value) != true)) {
this.CompaniesField = value;
this.RaisePropertyChanged("Companies");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] Countries {
get {
return this.CountriesField;
}
set {
if ((object.ReferenceEquals(this.CountriesField, value) != true)) {
this.CountriesField = value;
this.RaisePropertyChanged("Countries");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_DIVISION_M[] Divisions {
get {
return this.DivisionsField;
}
set {
if ((object.ReferenceEquals(this.DivisionsField, value) != true)) {
this.DivisionsField = value;
this.RaisePropertyChanged("Divisions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.LOCATION[] Locations {
get {
return this.LocationsField;
}
set {
if ((object.ReferenceEquals(this.LocationsField, value) != true)) {
this.LocationsField = value;
this.RaisePropertyChanged("Locations");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.REGION[] Regions {
get {
return this.RegionsField;
}
set {
if ((object.ReferenceEquals(this.RegionsField, value) != true)) {
this.RegionsField = value;
this.RaisePropertyChanged("Regions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Almarai.GiveAway.GetInitiatorList.ALM_WKFLW_TYPE_M[] WorkflowTypes {
get {
return this.WorkflowTypesField;
}
set {
if ((object.ReferenceEquals(this.WorkflowTypesField, value) != true)) {
this.WorkflowTypesField = value;
this.RaisePropertyChanged("WorkflowTypes");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
Reference:
public Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode) {
return base.Channel.GetInitiatorsListByWorkflow(userId, WorkflowTypeCode);
}
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflow", ReplyAction="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflowResponse")]
[System.ServiceModel.FaultContractAttribute(typeof(Almarai.GiveAway.GetInitiatorList.CustomFaultException), Action="http://tempuri.org/IMasterDataService/GetInitiatorsListByWorkflowCustomFaultExcep" +
"tionFault", Name="CustomFaultException", Namespace="http://schemas.datacontract.org/2004/07/Almarai.Web.Services.MasterData")]
Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST GetInitiatorsListByWorkflow(string userId, string WorkflowTypeCode);
Country class: (Should I change this class for Each different field like Company, Country, Region....so on)
public class CountryList
{
public CountryList(INITIATORS_LIST data)
{
ExtensionData = data;
}
public INITIATORS_LIST ExtensionData { get; internal set; }
}
My Method: (How should I modify my method)
[WebMethod]
public static List<CountryList> GetCountriesName(string UserID)
{
GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
string userid = "approver01";
string work = "4";
List<CountryList> countries = oClient.GetInitiatorsListByWorkflow(userid, work); // Error on this line
foreach (Country c in countries)
{
lst.Add(c.Name);
}
return lst; //Error on this line
}
I am not able to Add into list is there other approch ?
I know due to return type am not able to do but
The GetInitiatorsListByWorkflow method returns a Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST object, not a List<CountryList>. Likewise your GetCountriesName method returns List<CountryList>, not whatever the type of your (undefined in the code shown) lst variable is. That's why you have errors - you can't just randomly assign objects to variables which are the wrong type.
Anyway it seems that for your countries list you actually want to use two properties from the ALM_COUNTRY_M class. The INITIATORS_LIST contains an array of objects of that type.
So what you really need to do is get the array of ALM_COUNTRY_M objects from the INITIATORS_LIST returned by the GetInitiatorsListByWorkflow method, and loop through them, and for each one, create an equivalent instance of CountryList, set its properties using the values in the ALM_COUNTRY_M object, and add that to the list to be returned.
Something like this (untested):
[WebMethod]
public static List<CountryList> GetCountriesName(string UserID)
{
GetInitiatorList.MasterDataServiceClient oClient = new GetInitiatorList.MasterDataServiceClient();
string userid = "approver01";
string work = "4";
Almarai.GiveAway.GetInitiatorList.INITIATORS_LIST initiatorsList = oClient.GetInitiatorsListByWorkflow(userid, work); //get data from webservice
Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M[] countryMList = initiatorsList.Countries; //get list of countries from the data returned by the webservice
List<CountryList> countries = new List<CountryList>(); //create an empty list which will be populated with data from the webservice
//loop through list of countries returned from webservice
foreach (Almarai.GiveAway.GetInitiatorList.ALM_COUNTRY_M country in countryMList)
{
//add new instance of CountryList using fields from the webservice class
countries.Add(new CountryList() {
CountryCode = country.CountryCode,
CountryName = country.CountryName
});
}
return countries; //return the completed list of countries
}
The CountryList class should be defined more like this:
public class CountryList
{
public string CountryCode { get; set; }
public string CountryName { get; set; }
}
P.S. It would be more meaningful to rename the CountryList class to Country, since each object only represents a single country. It's the List<> part which defines a list. But that's a separate issue for you to decide.
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?
My soap service call is returning the following response:
<AssetList xmlns="http://schemas.datacontract.org/2004/07/XOSDigital.Assets" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Facets xmlns:a="http://schemas.datacontract.org/2004/07/XOSDigital.Business_Classes.Search"/>
<Results/>
<err i:nil="true"/>
<offset>0</offset>
<total>0</total>
</AssetList>
When I attempt to serialize this via:
AssetList assets;
var serializer = new XmlSerializer(typeof(AssetList));
assets = (AssetList)serializer.Deserialize(new MemoryStream(Encoding.UTF8.GetBytes(response.Content)));
I get the following exception:
<AssetList xmlns='http://schemas.datacontract.org/2004/07/XOSDigital.Assets'> was not expected.
The AssetList object I am trying to deserialize to was automatically generated by updating my service reference against the same exact service I am calling with my GET request.
Why is this failing?
The AssetList class is generated as:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="AssetList", Namespace="http://schemas.datacontract.org/2004/07/XOSDigital.Assets")]
[System.SerializableAttribute()]
public partial class AssetList : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private XOSDigital.XOSSuperfanAdminList.XosAssetWebService.AvailableFacetGroup[] FacetsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private XOSDigital.XOSSuperfanAdminList.XosAssetWebService.Asset[] ResultsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string errField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int offsetField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int totalField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public XOSDigital.XOSSuperfanAdminList.XosAssetWebService.AvailableFacetGroup[] Facets {
get {
return this.FacetsField;
}
set {
if ((object.ReferenceEquals(this.FacetsField, value) != true)) {
this.FacetsField = value;
this.RaisePropertyChanged("Facets");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public XOSDigital.XOSSuperfanAdminList.XosAssetWebService.Asset[] Results {
get {
return this.ResultsField;
}
set {
if ((object.ReferenceEquals(this.ResultsField, value) != true)) {
this.ResultsField = value;
this.RaisePropertyChanged("Results");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string err {
get {
return this.errField;
}
set {
if ((object.ReferenceEquals(this.errField, value) != true)) {
this.errField = value;
this.RaisePropertyChanged("err");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int offset {
get {
return this.offsetField;
}
set {
if ((this.offsetField.Equals(value) != true)) {
this.offsetField = value;
this.RaisePropertyChanged("offset");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int total {
get {
return this.totalField;
}
set {
if ((this.totalField.Equals(value) != true)) {
this.totalField = value;
this.RaisePropertyChanged("total");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
I think the problem is related with namespaces.
Can you try this?
var serializer = new XmlSerializer(typeof(AssetList),"http://schemas.datacontract.org/2004/07/XOSDigital.Assets");
Try to add this as the first line in your xml:
<?xml version="1.0"?>
Also, add XmlRoot attribute with namespace to your AssetList class:
[XmlRoot("AssetList", Namespace = "http://schemas.datacontract.org/2004/07/XOSDigital.Assets")]
In project i user SQL CE, i have Table:
[Table]
public class Article : INotifyPropertyChanged, INotifyPropertyChanging
{
// Define _cid: private field, public property, and database column.
private int _aid;
[Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true)]
public int aid
{
get { return _aid; }
set
{
NotifyPropertyChanging("aid");
_aid = value;
NotifyPropertyChanged("aid");
}
}
// Define nameColor name: private field, public property, and database column.
private int _rid;
[Column]
public int rid
{
get { return _rid; }
set
{
NotifyPropertyChanging("rid");
_rid = value;
NotifyPropertyChanged("rid");
}
}
private string _title;
[Column]
public string title
{
get { return _title; }
set
{
NotifyPropertyChanging("title");
_title = value;
NotifyPropertyChanged("title");
}
}
private string _thumnail;
[Column]
public string thumnail
{
get { return _thumnail; }
set
{
NotifyPropertyChanging("thumnail");
_thumnail = value;
NotifyPropertyChanged("thumnail");
}
}
private string _DesScription;
[Column(DbType = "NTEXT")]
public string DesScription
{
get { return _DesScription; }
set
{
NotifyPropertyChanging("DesScription");
_DesScription = value;
NotifyPropertyChanged("DesScription");
}
}
private int _orderID;
[Column]
public int orderID
{
get { return _orderID; }
set
{
NotifyPropertyChanging("orderID");
_orderID = value;
NotifyPropertyChanged("orderID");
}
}
private string _pubDate;
[Column]
public string pubDate
{
get { return _pubDate; }
set
{
NotifyPropertyChanging("pubDate");
_pubDate = value;
NotifyPropertyChanged("pubDate");
}
}
private string _linkURL;
[Column]
public string linkURL
{
get { return _linkURL; }
set
{
NotifyPropertyChanging("linkURL");
_linkURL = value;
NotifyPropertyChanged("linkURL");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
// Used to notify that a property changed
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region INotifyPropertyChanging Members
public event PropertyChangingEventHandler PropertyChanging;
// Used to notify that a property is about to change
private void NotifyPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
{
PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}
#endregion
}
when i Update Colum Thumnail , i have erros :
SQL Server does not handle comparison of NText, Text, Xml, or Image data types
because of special characters into database insert sequence trogn should I use BbType = "NTEXT"
Please Help me !
You could remove this column for concurrency checking by adding [Column(UpdateCheck = UpdateCheck.Never)] to this column.
See this blogpost about Linq to sql concurrency checking: http://blogs.msdn.com/b/matt/archive/2008/05/22/into-to-linq-to-sql-optimistic-concurrency.aspx