I need your help to solve my issue please give me a solution for this
I am trying a Serialize and Deserialize the Dynamic XML Data but the data was not Deserialized
These are my methods and i am using.
**Button Click Method**
protected void btnCreateSession_Click(object sender, EventArgs e)
{
tbodyException.Visible = false;
try
{
CreateSessionRequest request = new CreateSessionRequest();
(ucClientInfo)LoadControl("~Shared/UserControls/ucClientInfo.ascx");
request.applicationId = ucClientInfo1.txtApplicationID.Text;
request.accountType = ddlAccountType.SelectedValue;
request.salesOffice =
ddlSalesoffice.SelectedItem.ToString();
request.salesAgentId = txtAgentId.Text;
request.salesAgentName = txtAgentName.Text;
request.outletLocationId = txtOutletID.Text;
request.outletLocationName = txtOutletName.Text;
Dictionary<string, string> agentDetails = new Dictionary<string, string>();
agentDetails.Add("SubClientId", request.salesOffice);
agentDetails.Add("SalesAgentId", request.salesAgentId);
agentDetails.Add("SalesAgentName", request.salesAgentName);
Session.Add("AgentDetails", agentDetails);
ClientInfo clientinfo = new ClientInfo();
clientinfo = PreOrderingHelper.mapClientInfoDetails(clientinfo);
clientinfo.name = ucClientInfo1.txtClientName.Text;
clientinfo.clientId = ucClientInfo1.ddlClientID.SelectedValue;
GlobalVariable.ServiceClientID = ucClientInfo1.ddlClientID.SelectedValue;
request.client = clientinfo;
CreateSessionResponse response = new CreateSessionResponse();
string url = (Page.Master as TestBed).COAServiceUrl;
var token = (Page as BasePage).Token;
var _url = (Page as BasePage).AppUrl;
var _action = (Page as BasePage).Action + CurrentFlow.ToString();
bool localDebug = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["localDebug"]);
if (!localDebug)
{
ServiceHelper<CreateSessionRequest, CreateSessionResponse>(url);
var webRequest = (HttpWebRequest)CommonUtil.SendSOAPRequest(request, _url, CurrentFlow.ToString(), token, _action, false);
string result;
using (WebResponse resp = webRequest.GetResponse())
{
using (StreamReader rd = new StreamReader(resp.GetResponseStream()))
{
result = rd.ReadToEnd();
response = CommonUtil.DeserializeInnerSoapObject < CreateSessionResponse(result);
}
}
}
else
{
TextReader tr = new StreamReader(@"C:\SampleXmls\CreateSessionResp.xml");
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(CreateSessionResponse), "http://verizon.com/CoFEEAnywhere/CoAServices/v1");
response = xs.Deserialize(tr) as CreateSessionResponse;
}
if (response != null && response.output != null &&
!string.IsNullOrEmpty(response.output.sessionId))
{
Session["sessionId"] = response.output.sessionId;
(Page.Master.FindControl("lblGlobalSessionIDValue") as Label).Text = response.output.sessionId;
var masterPage = Page.Master as TestBed;
masterPage.SessionIdUpdatePanel.Update();
(Page as BasePage).SessionID = response.output.sessionId;
lblCreatedSession.Text = (Page as BasePage).SessionID;
lblSalesProfileResult.Text = "SUCCESS";
Session["ClientId"] = ucClientInfo1.ddlClientID.SelectedValue;
Session["ClientName"] = ucClientInfo1.txtClientName.Text;
Session["AppId"] = ucClientInfo1.txtApplicationID.Text;
Session["OrderType"] = ddlOrderType.SelectedValue;
Session["AccountType"] = ddlAccountType.SelectedValue;
}
}
catch (Exception ex)
{
tbodyException.Visible = true;
aExcpetion.InnerText = ex.Message + " | " + ex.InnerException != null ?
ex.InnerException.Message : string.Empty;
"OpenExceptionWindow('" + ex.InnerException + "');
}
finally
{
if (!string.IsNullOrEmpty(Session["ClientId"].ToString()) &&
Session["ClientId"].ToString() == "CETC")
{
var masterPage = Page.Master as TestBed;
masterPage.NextFlow.CommandName = FlowType.Recommended.ToString();
masterPage.NextFlow.Text = "Next";
masterPage.NextFlow.Visible = true;
}
else
{
var masterPage = Page.Master as TestBed;
masterPage.NextFlow.Visible = true;
}
}
}
** SOAP Request**
<pre>public static object SendSOAPRequest(object req, string _url, string methodName, string token, string _action, bool useSOAP12)
{
ServicePointManager.ServerCertificateValidationCallback = new
RemoteCertificateValidationCallback
(
delegate { return true; }
);
var formXml = new XmlDocument();
string soapXml = "";
soapXml = WsdlRequestToSOAP(req);
if (methodName == "GetBroadbandAvailability")
{
soapXml = soapXml.Remove(0, 21).Replace(methodName + "Request",
"gbbRequest");
}
else if (methodName == "GetQualifiedProducts")
{
soapXml = soapXml.Remove(0, 21).Replace(methodName + "Request",
"productsrequest");
}
else
{
soapXml = soapXml.Remove(0, 21).Replace(methodName + "Request", "req" +
methodName);
}
formXml.LoadXml(soapXml);
var newXml = new XmlDocument();
var rootTag = String.Format("<{0}></{0}>", methodName);
newXml.LoadXml(rootTag);
XmlNode rootNode = newXml.ImportNode(formXml.DocumentElement, true);
newXml.DocumentElement.AppendChild(rootNode);
var stringXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns=""http://some link""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
{0}
</soap:Body>
</soap:Envelope>";
var s = String.Format(stringXml, newXml.InnerXml);
formXml.LoadXml(s);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_url);
webRequest.Headers.Add("SOAPAction", _action ?? _url);
webRequest.ContentType = (useSOAP12) ? "application/soap+xml;charset=\"utf-8\"" :
"text/xml; encoding=utf-8";
webRequest.Accept = (useSOAP12) ? "application/soap+xml" : "text/xml";
webRequest.Method = "POST";
webRequest.Headers.Add("Authorization", "Bearer " + token);
webRequest.Headers.Add("X-CLIENT-CERT-STATUS", "ok");
webRequest.Headers.Add("X-SUBJECT-NAME", "C=US, ST=Florida, L=Temple Terrace, O =\"Verizon Data Services.LLC\", OU=GTSAP, CN=apigee.coasvcs.verizon.com");
using (Stream stream = webRequest.GetRequestStream())
{
formXml.Save(stream);
}
return webRequest;
}
** AuthorizeRequest**
<pre>public static string AuthorizeRequest()
{
string client_id = "t1ehVqcAGYmWC8yvPapwgdZOqOjQd5oO";
string client_secret = "ICo3o8Da8BCpmXk0";
var restClient = new RestClient("https://some link / oauth / client_credential / accesstoken ? grant_type = client_credentials");
var restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("Cache-Control", "no-cache");
restRequest.AddHeader("Content-Type", "application/json");
restRequest.AddParameter("client_id", client_id);
restRequest.AddParameter("client_secret", client_secret);
IRestResponse restResponse = restClient.Execute(restRequest);
var responseJson = restResponse.Content;
var token = JsonConvert.DeserializeObject<Dictionary<string, object>>
(responseJson)["access_token"].ToString();
return token;
}
** WsdlRequestToSOAP**
public static string WsdlRequestToSOAP(object Object)
{
if (Object == null)
{
throw new ArgumentException("Object can not be null");
}
try
{
var serxml = new System.Xml.Serialization.XmlSerializer(Object.GetType());
var ms = new MemoryStream();
serxml.Serialize(ms, Object);
return Encoding.UTF8.GetString(ms.ToArray());
}
catch { throw; }
}
** IndentXMLString**
public static string IndentXMLString(string xml)
{
string outXml = string.Empty;
MemoryStream ms = new MemoryStream();
XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.Unicode);
XmlDocument doc = new XmlDocument();
StreamReader sr = null;`enter code here`
try
{
doc.LoadXml(xml);
xtw.Formatting = System.Xml.Formatting.Indented;
doc.WriteContentTo(xtw);
xtw.Flush();
ms.Seek(0, SeekOrigin.Begin);
sr = new StreamReader(ms);
}
catch (Exception ex)
{
}
return sr.ReadToEnd();
}
<pre>** Finally this is the DeserializeInnerSoapObject method**
<pre>public static T DeserializeInnerSoapObject<T>(string soapResponse)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(soapResponse);
var soapBody = xmlDocument.GetElementsByTagName("s:Body")[0];
string innerObject = IndentXMLString(soapBody.InnerXml);
XmlSerializer deserializer = new XmlSerializer(typeof(T), "http://some link");
using (TextReader reader = new StringReader(innerObject))
{
return (T)deserializer.Deserialize(reader);
}
}
Finally the output came like this
<pre><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CreateSessionResponse xmlns="http://Some Link">
<CreateSessionResult>
<output>
<sessionId>some ID</sessionId>
</output>
</CreateSessionResult>
</CreateSessionResponse>
</soap:Body>
</soap:Envelope>
What I have tried:
I need your help to resolve this issue