I am getting this error after sending my request:
System.ServiceModel.FaultException`1[FinancierAPITester.SITCustomerServiceReference.ApiError]: Unable to process the request as an attempt was made to create an abstract class. (Fault Detail is equal to FinancierAPITester.SITCustomerServiceReference.ApiError).
When sending this request:
//MessageBox.Show("Running Add Contact Details Test!");
CustomerServiceClient customerServiceClient = new CustomerServiceClient();
AddContactDetailRequest addContactDetailsRequest = new AddContactDetailRequest();
AddContactDetailResponse addContactDetailsResponse = new AddContactDetailResponse();
addContactDetailsRequest.ContactDetails = new SITCustomerServiceReference.ContactDetail();
addContactDetailsRequest.UserName = "username";
addContactDetailsRequest.Password = "password";
addContactDetailsRequest.SystemToken = systemToken;
addContactDetailsRequest.CustomerNumber = "customerNumber";
addContactDetailsRequest.ContactDetails.SequenceNumber = 1;
In SOAP UI the request works fine like this (XML):
<ns:AddContactDetail>
<!--Optional:-->
<ns:request>
<!--Optional:-->
<data:AccessToken/>
<!--Optional:-->
<data:Password>${#Project#password}</data:Password>
<!--Optional:-->
<data:ProcessId/>
<!--Optional:-->
<data:SystemToken>${#Project#systemToken}</data:SystemToken>
<!--Optional:-->
<data:UserName>${#Project#username}</data:UserName>
<!--Optional:-->
<data:ContactDetails xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="data:Phone">
<data:FinancierContactDetail i:nil="true"/>
<data:FinancierLocationCode i:nil="true"/>
<data:FinancierTypeCode i:nil="true"/>
<data:SequenceNumber>1</data:SequenceNumber>
<data:Number>${#TestCase#phoneNumber}</data:Number>
<data:PhoneType>${#TestCase#phoneType}</data:PhoneType>
<data:UserId i:nil="true"/>
</data:ContactDetails>
<!--Optional:-->
<data:CustomerNumber>00100000000</data:CustomerNumber>
</ns:request>
</ns:AddContactDetail>
The main problem for me is that I cant find E-Mail/Phone type after typing in addContactDetailsRequest.ContactDetails. and so Obv I expect an error when not sending the actual main contact details.
This is the definition for .ContactDetails:
[System.Runtime.Serialization.DataMemberAttribute()]
public FinancierAPITester.SITCustomerServiceReference.ContactDetail ContactDetails {
get {
return this.ContactDetailsField;
}
set {
if ((object.ReferenceEquals(this.ContactDetailsField, value) != true)) {
this.ContactDetailsField = value;
this.RaisePropertyChanged("ContactDetails");
}
}
}
More Definitions if they help:
[System.Diagnostics.DebuggerStepThroughAttribute()[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ContactDetail", Namespace="URL")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(FinancierAPITester.SITCustomerServiceReference.Fax))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(FinancierAPITester.SITCustomerServiceReference.Email))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(FinancierAPITester.SITCustomerServiceReference.Phone))]
public partial class ContactDetail : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.Nullable<int> SequenceNumberField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Nullable<int> SequenceNumber {
get {
return this.SequenceNumberField;
}
set {
if ((this.SequenceNumberField.Equals(value) != true)) {
this.SequenceNumberField = value;
this.RaisePropertyChanged("SequenceNumber");
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Email", Namespace="http://financier.api.welcom.co.uk/2016/10/data")]
[System.SerializableAttribute()]
public partial class Email : FinancierAPITester.SITCustomerServiceReference.ContactDetail {
[System.Runtime.Serialization.OptionalFieldAttribute()]
private System.DateTime DateDeletedField;
private string EmailAddressField;
private FinancierAPITester.SITCustomerServiceReference.EmailType EmailTypeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string UserIdField;
[System.Runtime.Serialization.DataMemberAttribute()]
public System.DateTime DateDeleted {
get {
return this.DateDeletedField;
}
set {
if ((this.DateDeletedField.Equals(value) != true)) {
this.DateDeletedField = value;
this.RaisePropertyChanged("DateDeleted");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public string EmailAddress {
get {
return this.EmailAddressField;
}
set {
if ((object.ReferenceEquals(this.EmailAddressField, value) != true)) {
this.EmailAddressField = value;
this.RaisePropertyChanged("EmailAddress");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute(IsRequired=true)]
public FinancierAPITester.SITCustomerServiceReference.EmailType EmailType {
get {
return this.EmailTypeField;
}
set {
if ((this.EmailTypeField.Equals(value) != true)) {
this.EmailTypeField = value;
this.RaisePropertyChanged("EmailType");
}
}
}
How do I add this Phone/Email/Fax type? So I can actually send the request with the E-Mail/Phone/Fax.
Thanks
The problem was I had to initialise it first then fill in the instances like below:
addContactDetailsRequest.ContactDetails = new SITCustomerServiceReference.Phone();
SITCustomerServiceReference.Phone phoneContactDetails = new Phone();
phoneContactDetails.Number = "01772444444";
phoneContactDetails.PhoneType = SITCustomerServiceReference.PhoneType.Home;
string currentDateString = "2017/06/11T00:00:00";
DateTime currentDate = Convert.ToDateTime(currentDateString);
phoneContactDetails.DateDeleted = currentDate;
addContactDetailsRequest.UserName = "UserName ";
addContactDetailsRequest.Password = "Password ";
addContactDetailsRequest.SystemToken = systemToken;
addContactDetailsRequest.CustomerNumber = "00123456789";
addContactDetailsRequest.ContactDetails.SequenceNumber = 1;
addContactDetailsRequest.ContactDetails = phoneContactDetails;
Then when it comes to including the email in the request itself just add reference it to the object of which you filled in all the details of after initialising.
Related
Trying to create a web api using c# .net which will take following input
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUser xmlns="http://tempuri.org/">
<UserRecorder>
<COMPANY>string</COMPANY>
<PASSWORD>string</PASSWORD>
<USER>string</USER>
<UserRecord>
<item>
<ST>1</ST>
<LT>1</LT>
<TNO>ABC</TNO>
</item>
</UserRecord>
</UserRecorder>
</GetUser>
</soap:Body>
</soap:Envelope>
and should return the following output in XML
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetUserResponse xmlns="http://tempuri.org/">
<UserRecorder.Response>
<Company>string</Company>
<UserRecord.Response>
<item>
<ST>int</ST>
<LT>int</LT>
<TNo>string</TNo>
<ADate>string</ADate>
<ATime>string</ATime>
<LAT>string</LAT>
<LON>string</LON>
</item>
</UserRecord.Response>
</UserRecorder.Response>
</GetUserResponse>
</soap12:Body>
</soap12:Envelope>
==== WHAT I DID TILL NOW ===
Input step done as you can see below XML input generated from API link
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUser xmlns="http://tempuri.org/">
<UserRecorder>
<COMPANY>string</COMPANY>
<PASSWORD>string</PASSWORD>
<USER>string</USER>
<UserRecord>
<item>
<ST>int</ST>
<LT>int</LT>
<TNO>string</TNO>
</item>
</UserRecord>
</UserRecorder>
</GetUser>
</soap:Body>
</soap:Envelope>
Now I am facing issue to generating same response as shared above. My response coming as follow: by using POSTMAN
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetUserResponse xmlns="http://tempuri.org/">
<GetUserResult><?xml version="1.0" encoding="utf-8"?><UserRecorder xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Company>TW</Company><UserRecord><item><ST>1</ST><LT>1</LT><TNo>4582</TNo><ADate>20210415</ADate><ATime>20:00:00</ATime><LAT>65.25</LAT><LON>108.24</LON></item></UserRecord></UserRecorder></GetUserResult>
</GetUserResponse>
</soap:Body>
</soap:Envelope>
My Code snippet as follows:
//CUserResponse class
public class CUserResponse
{
public class UserRecorder
{
private string company;
public string Company
{
get { return company; }
set { company = value; }
}
private UserRecord eTA_TRACK;
public UserRecord UserRecord
{
get { return eTA_TRACK; }
set { eTA_TRACK = value; }
}
}
public class UserRecord
{
private Item roots;
public Item item
{
get { return roots; }
set { roots = value; }
}
}
public class Item
{
int sALES_TYPE;
int lOCATION_TYPE;
string tANK_LORRY_NO = string.Empty;
string aLERT_DATE = string.Empty;
string aLERT_TIME = string.Empty;
string lOCATION_COORDINATES_LAT = string.Empty;
string lOCATION_COORDINATES_LON = string.Empty;
public int ST
{
get { return sALES_TYPE; }
set { sALES_TYPE = value; }
}
public int LT
{
get { return lOCATION_TYPE; }
set { lOCATION_TYPE = value; }
}
public string TNo
{
get { return tANK_LORRY_NO; }
set { tANK_LORRY_NO = value; }
}
public string ADate
{
get { return aLERT_DATE; }
set { aLERT_DATE = value; }
}
public string ATime
{
get { return aLERT_TIME; }
set { aLERT_TIME = value; }
}
public string LAT
{
get { return lOCATION_COORDINATES_LAT; }
set { lOCATION_COORDINATES_LAT = value; }
}
public string LON
{
get { return lOCATION_COORDINATES_LON; }
set { lOCATION_COORDINATES_LON = value; }
}
}
}
/// End of CUserResponse class
And asmx code is below:
//asmx code snippet
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class KECommWebService : System.Web.Services.WebService
{
#region API
public class Item
{
int sALES_TYPE;
int lOCATION_TYPE;
string tANK_LORRY_NO = string.Empty;
public int ST
{
get { return sALES_TYPE; }
set { sALES_TYPE = value; }
}
public int LT
{
get { return lOCATION_TYPE; }
set { lOCATION_TYPE = value; }
}
public string TNO
{
get { return tANK_LORRY_NO; }
set { tANK_LORRY_NO = value; }
}
}
public class UserRecord
{
private Item roots;
public Item item
{
get { return roots; }
set { roots = value; }
}
}
public class UserRecorder
{
private string company;
private string password;
private string user;
public string COMPANY
{
get { return company; }
set { company = value; }
}
public string PASSWORD
{
get { return password; }
set { password = value; }
}
public string USER
{
get { return user; }
set { user = value; }
}
private UserRecord eTA_TRACK;
public UserRecord UserRecord
{
get { return eTA_TRACK; }
set { eTA_TRACK = value; }
}
}
[WebMethod]
public string GetUser(UserRecorder UserRecorder)
{
CUserResponse.UserRecorder cETAResponse = new CUserResponse.UserRecorder();
cETAResponse.Company = "TW";
CUserResponse.UserRecord eTA_TRACKResponse = new CUserResponse.UserRecord();
CUserResponse.Item itemresponse = new CUserResponse.Item();
itemresponse.ST = 1;
itemresponse.LT = 1;
itemresponse.ADate = "20210415";
itemresponse.ATime = "20:00:00";
itemresponse.LAT = "65.25";
itemresponse.LON = "108.24";
itemresponse.TNo = "4582";
eTA_TRACKResponse.item = itemresponse;
cETAResponse.UserRecord = eTA_TRACKResponse;
Type t = cETAResponse.GetType();
var xml = "";
using (StringWriter sww = new Utf8StringWriter())
{
using (XmlWriter writer = XmlWriter.Create(sww))
{
var ns = new XmlSerializerNamespaces();
// add empty namespace
//ns.Add("", "");
XmlSerializer xsSubmit = new XmlSerializer(t);
xsSubmit.Serialize(writer, cETAResponse, ns);
xml = sww.ToString(); // Your XML
}
}
return xml;
}
public class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
#endregion
}
//END of asmx code snippet
Pl guide...
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?
I am new to SOAP Webservice. Please suggest me how to achieve following XML
I'm trying to generate C# that creates a fragment of XML like this.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<querySeatResponse xmlns="xxx">
<querySeatResult>
<querySeat_status code="int" msg="string">
<details>
<detail seat_no="string" available="string" />
<detail seat_no="string" available="string" />
</details>
</querySeat_status>
</querySeatResult>
</querySeatResponse>
</soap:Body>
</soap:Envelope>
But I am getting following Output :
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<querySeatResponse xmlns="xxx">
<querySeatResult>
<querySeat_status code="int" msg="string">
<details>
<detail xsi:nil="true" />
<detail xsi:nil="true" />
</details>
</querySeat_status>
</querySeatResult>
</querySeatResponse>
</soap:Body>
</soap:Envelope>
My Source Code as follows :
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class abc : System.Web.Services.WebService
{
[WebMethod]
[SoapDocumentMethod("xxx", RequestNamespace = "xxx", ResponseNamespace = "xxx", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public querySeat_Main querySeat([XmlAttribute] string signature, string operator_code, string route_id, string trip_no, string depart_date, string counter_from, string counter_to, string bus_type)
{
querySeat_Main main = new querySeat_Main();
querySeat_status status = new querySeat_status();
querySeat_status.detail detail = new querySeat_status.detail();
status.code = 0;
status.msg = "success";
main.querySeat_status = status;
return main;
}
}
[Serializable]
[GeneratedCode("System.Xml", "xxxx")]
[XmlType(Namespace = "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
public class querySeat_Main
{
querySeat_status status;
public querySeat_Main()
{
}
public querySeat_status querySeat_status { get { return status; } set { status = value; } }
}
[Serializable]
[GeneratedCode("System.Xml", "xxx")]
[XmlType(Namespace = "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
[XmlRoot("querySeat_status", Namespace = "xxx")]
public class querySeat_status
{
int Code;
string Msg;
public querySeat_status() { }
[XmlAttribute]
public int code { get { return Code; } set { Code = value; } }
[XmlAttribute]
public string msg { get { return Msg; } set { Msg = value; } }
[XmlArray("details")]
[XmlArrayItem("detail")]
public List<detail> details = new List<detail>();
[Serializable]
[GeneratedCode("System.Xml", "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
[XmlRoot("querySeat_status", Namespace = "xxx")]
public class detail
{
string seat;
string avail;
public detail() { }
[XmlAttribute]
public string seat_no { get { return seat; } set { seat = value; } }
[XmlAttribute]
public string available { get { return avail; } set { avail = value; } }
}
}
As mentioned by Alex, looks like you don't initialize your details, you can try:
public querySeat_Main querySeat([XmlAttribute] string signature, string operator_code, string route_id, string trip_no, string depart_date, string counter_from, string counter_to, string bus_type)
{
querySeat_Main main = new querySeat_Main();
querySeat_status status = new querySeat_status();
querySeat_status.detail detail = new querySeat_status.detail();
detail.available = "no";
detail.seat_no = "7";
status.code = 0;
status.details = new List<querySeat_status.detail>();
status.details.Add(detail);
status.msg = "success";
main.querySeat_status = status;
return main;
}
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")]
I need to be able to define two nodes with the same name but completely different subnode structures. I didn't design this XML schema but for the time being I'm forced to use it as is. I realize it's a terrible abuse of everything that is XML but there you have it.
What I need it to look like:
<order>
<ItemType type="Clubs">
<Club num="1">
<ClubName>Some Name</ClubName>
<ClubChoice>Something Else</ClubChoice>
</Club>
</ItemType>
<ItemType type="Gift" val="MailGreeting">
<GiftName>MailGreeting</GiftName>
<GiftDescription></GiftDescription>
<GiftQuanity>1</GiftQuanity>
</ItemType
</order>
Of course it's far more complicated than but you get the gist.
I'm using XmlSerializer and would really like to avoid using XDocument but if that's what I need to do then so be it.
If your order contains properties and not a list you can tell the serializer to name the elements like this:
[XmlRoot("order")]
public class Order
{
private Whatever whateverInstance;
[XmlElement("ItemType")]
public Whatever WhateverInstance
{
get { return whateverInstance; }
set { whateverInstance = value; }
}
private Something somethingInstance;
[XmlElement("ItemType")]
public Something SomethingInstance
{
get { return somethingInstance; }
set { somethingInstance = value; }
}
}
If it's a list of things you could get to have a identical element name as well but you will get a redundant xsi:Type attribute:
[XmlRoot("order")]
public class Order
{
private ItemType[] itemTypes;
[XmlElement("ItemType")]
public ItemType[] ItemTypes
{
get { return itemTypes; }
set { itemTypes = value; }
}
}
[XmlInclude(typeof(Clubs))]
[XmlInclude(typeof(Gift))]
public abstract class ItemType
{
private string type = "None";
[XmlAttribute]
public string Type
{
get { return type; }
set { type = value; }
}
}
public class Clubs : ItemType
{
public Clubs()
{
Type = "Clubs";
}
private Club[] clubsArray;
[XmlElement("Club")]
public Club[] ClubsArray
{
get { return clubsArray; }
set { clubsArray = value; }
}
}
public class Club
{
private int num = 0;
[XmlAttribute("num")]
public int Num
{
get { return num; }
set { num = value; }
}
private string clubName = "";
public string ClubName
{
get { return clubName; }
set { clubName = value; }
}
private string clubChoice = "";
public string ClubChoice
{
get { return clubChoice; }
set { clubChoice = value; }
}
}
public class Gift : ItemType
{
public Gift()
{
Type = "Gift";
}
private string val = "";
[XmlAttribute("val")]
public string Val
{
get { return val; }
set { val = value; }
}
private string giftName = "";
public string GiftName
{
get { return giftName; }
set { giftName = value; }
}
private string giftDescription = "";
public string GiftDescription
{
get { return giftDescription; }
set { giftDescription = value; }
}
private int giftQuanity = 0;
public int GiftQuanity
{
get { return giftQuanity; }
set { giftQuanity = value; }
}
}
Test:
List<ItemType> list = new List<ItemType>();
list.Add(new Clubs() { ClubsArray = new Club[] { new Club() { Num = 0, ClubName = "Some Name", ClubChoice = "Something Else" } } });
list.Add(new Gift() { Val = "MailGreeting", GiftName = "MailGreeting", GiftDescription = "GiftDescription", GiftQuanity = 1});
Order order = new Order();
rder.ItemTypes = list.ToArray();
XmlSerializer serializer = new XmlSerializer(typeof(Order));
StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Stuff.xml");
serializer.Serialize(sw, order);
sw.Close();
Output:
<order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ItemType xsi:type="Clubs" Type="Clubs">
<Club num="0">
<ClubName>Some Name</ClubName>
<ClubChoice>Something Else</ClubChoice>
</Club>
</ItemType>
<ItemType xsi:type="Gift" Type="Gift" val="MailGreeting">
<GiftName>MailGreeting</GiftName>
<GiftDescription>GiftDescription</GiftDescription>
<GiftQuanity>1</GiftQuanity>
</ItemType>
</order>