I have a Restful WCF method that is returning 2 object(2 different class) base on condition inside the method.
This is my method:
public Model.BaseType returnPayment_Gateway()
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
Model.Payment_Gateway payment_Gateway=null;
if (headers["ServiceAuthentication"] != null)
{
string ServiceAuthentication = headers["ServiceAuthentication"].ToString();
bool serviceAuth = Service_Authentication(ServiceAuthentication);
DAL.DataManager dal = new DAL.DataManager();
if (serviceAuth == true)
{
payment_Gateway = dal.Get_Payment_Gateway();
}
}
else
{
// Create a new response to return
return new Model.ReturnResponse() { StatusCode = 201, StatusDescription = "Authentication Fails" };
}
return payment_Gateway;
}
This is my base class that contains both of objects:
[Serializable]
[DataContract]
[KnownType(typeof(Payment_Gateway))]
[KnownType(typeof(ReturnResponse))]
public class BaseType
{
}
this is one of the derived classes:
[DataContract]
public class Payment_Gateway:BaseType
{
[DataMember]
public string Gateway { get; set; }
and this is another drived class:
[DataContract]
public class ReturnResponse:BaseType
{
[DataMember]
public int StatusCode { get; set; }
[DataMember]
public string StatusDescription { get; set; }
This is in my .SVC how I call this method:
public Model.BaseType Payment_Gateway()
{
return GetCustomerInfo.Instance.returnPayment_Gateway();
}
and this is my service interface:
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "Payment_Gateway")]
Model.BaseType Payment_Gateway();
My question:
The Json response that I am getting has 1 extra line that I am not sure where it comes from and how to remove it. this line:
"__type": "Payment_Gateway:#CustomerPortal.Model",
This is complete response I am getting in Soap UI.
{
"__type": "Payment_Gateway:#CustomerPortal.Model",
"Gateway": "[\r\n {\"Payment_Gateway_ID\":\"40\",\"Payment_Gateway_Name\":\"Speedpay\",\"Payment_Gateway_URL\":\"https:\\/\\/paynow7.speedpay.com\\/CarFinance\\/index.asp\",\"Payment_Gateway_Description\":\"Speedpay is a Third-party bill payment vendor that provides CarFinance.com's customers the convenience and flexibility of making electronic payments, along with the security and peace-of-mind that comes from retaining total control over your bills. Western Union Speedpay charges a convenience fee of $10. CarFinance.com does not receive any portion of the convenience fee. The fee, which is in addition to your car payment, is paid directly to Western Union Speedpay for providing this service to our customers.\"},\r\n {\"Payment_Gateway_ID\":\"41\",\"Payment_Gateway_Name\":\"Western Union - Quick Collect\",\"Payment_Gateway_URL\":\"https:\\/\\/www.westernunion.com\\/us\\/en\\/home.html\",\"Payment_Gateway_Description\":\"Western Union Quick Collect service is a fast and convenient way to deliver funds -- especially on a due date! Within minutes of your completed payment transaction, Quick Collect delivers an electronic fund transfer notification to CarFinance.com. Western Union charges a $10 service fee that typically is less expensive than the cost of overnight delivery. Please note: This Western Union service will accept cash only.\"},\r\n {\"Payment_Gateway_ID\":\"42\",\"Payment_Gateway_Name\":\"MoneyGram\",\"Payment_Gateway_URL\":\"http:\\/\\/moneygram.com\\/us\\/en\",\"Payment_Gateway_Description\":\"MoneyGram Bill Payments Services is set up to allow consumers make payments to CarFinance.com. MoneyGram charges a fee of $9.99 for this service. CarFinance.com does not receive any portion of the convenience fee. The fee, which is in addition to your car payment, is paid directly to MoneyGram for providing this service to our customers. Bill Payment Services also enable consumers to load and reload prepaid debit cards. To find an agent near you or pay online, go to \"},\r\n {\"Payment_Gateway_ID\":\"43\",\"Payment_Gateway_Name\":\"Mail your payment\",\"Payment_Gateway_URL\":\"\",\"Payment_Gateway_Description\":\"Payments are processed and posted to accounts Monday through Friday (excluding holidays). Please allow 10 days for mailing if you're mailing your payment.\\r\\n\\r\\nCarFinance\\r\\nPO Box 660057\\r\\nDallas, TX 75266-0057\"}\r\n]"
}