« Back to Administration XML Questions

Error updating pin with SOAP request

Combination View Flat View Tree View
Threads [ Previous | Next ]
HI All, I'm trying to update users Pin number with a .Net C# webpage.
I have pasted the code and error below.  I ended up using soap although I noticed there is a risservice.wsdl that should have methods to update pins.  Any help would be greatly appreciated.
code
----------------------
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Net.Mail;
using System.Net.Mime;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;
using System.Text;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
 
 
    }
 
 
    protected void Button1_Click(object sender, EventArgs e)
    {
 
        try
        {
 
            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://ip:8443/axl/"));
            request.ProtocolVersion = System.Net.HttpVersion.Version10;
            request.Credentials = new NetworkCredential("user", "pass");
            request.Timeout = 100000;
            request.Method = "POST";
            request.ContentType = "text/xml";
 
            String axlSoapRequest = null;
            String axlRequestEnvelope = null;
 
            axlSoapRequest = "POST /axl/ HTTP/1.0\r\n";
            axlSoapRequest += "Host: host:8443 \r\n"; axlSoapRequest += "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(("user" + ":" + "pass"))) + "==\r\n";
            axlSoapRequest += "Accept: text/*\r\n";
            axlSoapRequest += "Content-type: text/xml\r\n";
            axlSoapRequest += "SOAPAction: \"CUCMemoticonB ver=8.0\"\r\n";
            axlSoapRequest += "Content-length: ";
            axlRequestEnvelope = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/8.5\"> ";
            axlRequestEnvelope += "<soapenv:Header/>";
            axlRequestEnvelope += "<soapenv:Body>";
            axlRequestEnvelope += "<ns:updateUser sequence=\"?\">";
            axlRequestEnvelope += "<userid>user</userid>";
            axlRequestEnvelope += "<password>user pass</password>";
            axlRequestEnvelope += "<pin>new pin</pin>";
            axlRequestEnvelope += "</ns:updateUser>";
            
            
            axlRequestEnvelope += "</soapenv:Body> ";
            axlRequestEnvelope += "</soapenv:Envelope>";
            axlSoapRequest += axlRequestEnvelope.ToString();
            axlSoapRequest += "\r\n\r\n";
 
 
           
 
 
 
 
            Stream requestStream = request.GetRequestStream();
 
            requestStream.Write(System.Text.Encoding.ASCII.GetBytes(axlSoapRequest), 0, axlSoapRequest.Length);
            requestStream.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
 
            Label1.Text = readStream.ReadToEnd();
 
            Response.ContentType = "text/xml";
            Response.Charset = "utf-8";
            Response.Write(readStream.ReadToEnd());
            
 
        }
        catch (Exception ex)
        { 
        
        }  
    
    }
}
 
this is the error that is printed to the page
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">


  <SOAP-ENV:Header />


- <SOAP-ENV:Body>


- <SOAP-ENV:Fault>


  <faultcode>SOAP-ENV:Client</faultcode>


  <faultstring>Content is not allowed in prolog.</faultstring>


- <detail>


- <axl:Error xmlns:axl="http://www.cisco.com/AXL/API/1.0">


  <axl:code>5001</axl:code>


  <axl:message>Content is not allowed in prolog.</axl:message>


  <request />

  </axl:Error>


  </detail>


  </SOAP-ENV:Fault>


  </SOAP-ENV:Body>


  </SOAP-ENV:Envelope>

 

The error usually means that the beginning of the XML is somehow corrupt/malformed.

From your code, it looks like you are appending the Content-Length header - with no actual content length value or terminating carriage-return/life-feed - and then immediately starting in  with the XML.  This probably looks like a badly malformed Content-Length header followed by a body containing nothing.

I think you need to do something like:
- Create/concatenate the XML payload in a string variable
- Calculate the XML variable's length
- In a new variable start building/concatenating the headers, including Content-Length header, with the value calculated above, and terminating CR/LF
- Append an intervening CR/LF (to terminate the header part of the packet)
- Append the XML
 

Thanks David, I took your suggestions and got the following response:
This looks like a successful response yes?  I am working with the our engireers to see if the pin was in fact updated...

- <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">


  <SOAP-ENV:Header />


- <SOAP-ENV:Body>


- <axl:updateUserResponse sequence="?" xmlns:axl="http://www.cisco.com/AXL/API/6.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


  <return>{29B11E42-4B4E-4EA3-B1DF-482CB0CEAAC4}</return>

  </axl:updateUserResponse>


  </SOAP-ENV:Body>


  </SOAP-ENV:Envelope>
 
 

Response looks right...the return value should be the primary key (uuid) of the effected device.

Thanks for you help on this David, very much appreciated!
Here is the final code in case anyone else comes across this issue:

using

 

System;


using

 

System.Net;


using

 

System.Collections.Generic;


using

 

System.Linq;


using

 

System.Web;


using

 

System.Web.UI;


using

 

System.Web.UI.WebControls;


using

 

System.Xml;


using

 

System.Net.Mail;


using

 

System.Net.Mime;


using

 

System.Data;


using

 

System.Configuration;


using

 

System.Web.Security;


using

 

System.Web.UI.WebControls.WebParts;


using

 

System.Web.UI.HtmlControls;


using

 

System.Collections;


using

 

System.Data.SqlClient;


using

 

System.Text;


using

 

System.Runtime.InteropServices;


using

 

System.Xml.Serialization;


using

 

System.ComponentModel;


using

 

System.Diagnostics;


using

 

System.Globalization;


using

 

System.IO;


public

 
partial class _Default : System.Web.UI.

Page



{

 

protected void Page_Load(object sender, EventArgs
e)
{

 

 

}

 

 


protected void Button1_Click(object sender, EventArgs
e)
{

 




try



{

 

String axlSoapRequest = null
;
 


String axlRequestEnvelope = null
;
axlRequestEnvelope =


"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/8.5\"> "
;
axlRequestEnvelope +=


"<soapenv:Header/>"
;
axlRequestEnvelope +=


"<soapenv:Body>"
;
axlRequestEnvelope +=


"<ns:updateUser sequence=\"?\">"
;
axlRequestEnvelope +=


"<userid>user</userid>"
;
axlRequestEnvelope +=


"<password>pass</password>"
;
axlRequestEnvelope +=


"<pin>pin</pin>"
;
axlRequestEnvelope +=


"</ns:updateUser>"
;
axlRequestEnvelope +=


"</soapenv:Body> "
;
axlRequestEnvelope +=


"</soapenv:Envelope>"
;
 

 


ServicePointManager.ServerCertificateValidationCallback += delegate { return true
; };
 


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://:8443/axl/"
));
request.ProtocolVersion = System.Net.


HttpVersion
.Version10;
request.Credentials =


new NetworkCredential("user", "pass"
);
request.Timeout = 100000;

request.Method =


"POST"
;
request.ContentType =


"text/xml; charset=utf-8"
;
request.Accept =


"text/xml"
;
request.ContentLength = axlRequestEnvelope.Length;








 

Stream
requestStream = request.GetRequestStream();
requestStream.Write(System.Text.


Encoding
.ASCII.GetBytes(axlRequestEnvelope), 0, axlRequestEnvelope.Length);
requestStream.Close();

 


HttpWebResponse response = (HttpWebResponse
)request.GetResponse();
 


Stream
responseStream = response.GetResponseStream();
 


StreamReader readStream = new StreamReader(responseStream, Encoding
.UTF8);
Label1.Text = readStream.ReadToEnd();

Response.ContentType =


"text/xml"
;
Response.Charset =


"utf-8"
;
Response.Write(readStream.ReadToEnd());

 

 

 

 

 

 

 

 

}

 


catch (Exception
ex)
{

 

}

 

 

}

}

using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Net.Mail;
using System.Net.Mime;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;
using System.Text;
using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            String axlSoapRequest = null;
            String axlRequestEnvelope = null;
            axlRequestEnvelope = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/8.5\"> ";
            axlRequestEnvelope += "<soapenv:Header/>";
            axlRequestEnvelope += "<soapenv:Body>";
            axlRequestEnvelope += "<ns:updateUser sequence=\"?\">";
            axlRequestEnvelope += "<userid>user</userid>";
            axlRequestEnvelope += "<password>pass</password>";
            axlRequestEnvelope += "<pin>pin</pin>";
            axlRequestEnvelope += "</ns:updateUser>";
            axlRequestEnvelope += "</soapenv:Body> ";
            axlRequestEnvelope += "</soapenv:Envelope>";

            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://:8443/axl/"));
            request.ProtocolVersion = System.Net.HttpVersion.Version10;
            request.Credentials = new NetworkCredential("user", "pass");
            request.Timeout = 100000;
            request.Method = "POST";
            request.ContentType = "text/xml; charset=utf-8";
            request.Accept = "text/xml";
            request.ContentLength = axlRequestEnvelope.Length;
           // request.ContentLength =
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(System.Text.Encoding.ASCII.GetBytes(axlRequestEnvelope), 0, axlRequestEnvelope.Length);
            requestStream.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
            Label1.Text = readStream.ReadToEnd();
            Response.ContentType = "text/xml";
            Response.Charset = "utf-8";
            Response.Write(readStream.ReadToEnd());
          

          
 

          
           
        }
        catch (Exception ex)
        {
       
        }
       
   
    }
}