473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

hexadecimal value 0x00, is an invalid character error

Hello

I am getting the following error message when I try and send an XML sting to
a web service, I read somewhere that most web services prefer ascii and some
throw errors when using unicode so I have changed the encoding but still cant
get rid of the error.

System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
reader) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters) at
SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in
C:\temp\SMS\Authenticate.aspx:line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile><SMSMessage><MessageID>1</MessageID><MessageText>test</MessageText><Destination>40123123</Destination></SMSMessage></SMSBatchFile>";
Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

Has anyone encountered this?
Nov 23 '05 #1
6 31931
Well, nulls don't show up when you look at raw text, they're usually
encoded safely in a string so they don't show up when you look at them.
i could be wrong about that, though, its been a long time since i've
fiddled with nulls in text.

if you copy/pasted that string, i'd type it in by hand and try again.
can't get a null in that way.

jeremiah

jasn wrote:
Hello

I am getting the following error message when I try and send an XML sting to
a web service, I read somewhere that most web services prefer ascii and some
throw errors when using unicode so I have changed the encoding but still cant
get rid of the error.

System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
reader) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters) at
SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in
C:\temp\SMS\Authenticate.aspx:line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile><SMSMessage><MessageID>1</MessageID><MessageText>test</MessageText><Destination>40123123</Destination></SMSMessage></SMSBatchFile>";
Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

Has anyone encountered this?

Nov 23 '05 #2
Thats what I originally thought but Ive also tried creating the string using
XmlTextWriter and this still gives me the same error message.
"jeremiah johnson" wrote:
Well, nulls don't show up when you look at raw text, they're usually
encoded safely in a string so they don't show up when you look at them.
i could be wrong about that, though, its been a long time since i've
fiddled with nulls in text.

if you copy/pasted that string, i'd type it in by hand and try again.
can't get a null in that way.

jeremiah

jasn wrote:
Hello

I am getting the following error message when I try and send an XML sting to
a web service, I read somewhere that most web services prefer ascii and some
throw errors when using unicode so I have changed the encoding but still cant
get rid of the error.

System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
reader) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters) at
SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in
C:\temp\SMS\Authenticate.aspx:line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile><SMSMessage><MessageID>1</MessageID><MessageText>test</MessageText><Destination>40123123</Destination></SMSMessage></SMSBatchFile>";
Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

Has anyone encountered this?

Nov 23 '05 #3
Hi,

I also do not see any reason for the 0x00 to show up. There are a few
things that spring to my mind;

- I'm not clear on the String->Byte[]->String conversion code you
provided at the bottom of your post. Is this code you used to check or
part of the implementation you are using?
WebServices work with XML 1.0 + Namespaces, so if you're not using the
XmlSerializer's, the easiest way to deal with this is either a
DOMDocument or A Streaming XML API (XmlWriter).

Can you post the code that "builds & posts the XML message" to the
webservice?

Hope this helps,

Marvin Smit.
On Wed, 26 Oct 2005 22:49:57 -0500, jeremiah johnson
<na*******@gmail.com> wrote:
Well, nulls don't show up when you look at raw text, they're usually
encoded safely in a string so they don't show up when you look at them.
i could be wrong about that, though, its been a long time since i've
fiddled with nulls in text.

if you copy/pasted that string, i'd type it in by hand and try again.
can't get a null in that way.

jeremiah

jasn wrote:
Hello

I am getting the following error message when I try and send an XML sting to
a web service, I read somewhere that most web services prefer ascii and some
throw errors when using unicode so I have changed the encoding but still cant
get rid of the error.

System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
reader) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters) at
SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in
C:\temp\SMS\Authenticate.aspx:line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile><SMSMessage><MessageID>1</MessageID><MessageText>test</MessageText><Destination>40123123</Destination></SMSMessage></SMSBatchFile>";
Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

Has anyone encountered this?

Nov 23 '05 #4
Thanks for your response.

Ive tried with and without the String->Byte[]->String conversion and tried
using XMLTextWriter to build the string but this still causes problems.

This is my aspx page:-
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="XMLMethods" %>
<%@ import Namespace="SMSservices" %>
<%@ import Namespace="Authenticate" %>
<script runat="server">

// Insert page code here

SMSAuthentication oSec = new SMSAuthentication();
SMSServices oClient = new SMSServices();
XMLMethods xm = new XMLMethods();

string Username = "test";
string Password = "test";
string messageStr = "";
string messageStatus = "";
string returnKey = "";
string strXML = "";
string Key;
string sXMLRet = "Key";
string proxy = "http://hmt-pxy-2.test.com:8080";

protected void Page_Load(Object Src, EventArgs E)
{
//Authenticate with proxy using default or my login info
if(!"".Equals(proxy))
{
WebProxy proxyObject = new WebProxy(proxy);

// Disable proxy use when the host is local.
proxyObject.BypassProxyOnLocal = true;

//Set proxy Credentials to authenticate on server
//proxyObject.Credentials =
System.Net.CredentialCache.DefaultCredentials;
proxyObject.Credentials = new NetworkCredential("test",
"test", "test");

// HTTP requests use this proxy information.
GlobalProxySelection.Select = proxyObject;

}

// Create Message XML string
messageStr = xm.BuildSendXML("1","Snippets please","44773423432");

try {
//strXML = messageStr

Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

}
catch(Exception e) {
sXMLRet = "<p>ERROR: XML String parse: Please contact
test</p><p>"+e+"</p>";
}

//'Login to obtain valid key
try {
oSec.clientLogin(Username,Password,ref Key);
}
catch(Exception e) {
sXMLRet = "<p>ERROR: Login Failed: Please contact
test</p><p>"+e+"</p>";
}

if (Key != null)
{
try {
returnKey = oClient.sendSMSsender(strXML, "44773423432", Key);
try {

sXMLRet =
oClient.getBatchMessageStatus(messageStatus,Key);

} catch(Exception e){
sXMLRet = "ERROR: Get Message Status Error<br>please
contact test<BR>"+e;
}
}
catch(Exception e){
sXMLRet = "ERROR: Send Message Error<br>please contact
test<br><br>"+e;
}
}

}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<p>
<%=returnKey%>
</p>
<p>
<%=strXML%>
</p>
<p>
<%=sXMLRet%>
</p>
</form>
</body>
</html>
and this is the class that I use to build the XML:-

// XMLMethods.cs
//

namespace XMLMethods {
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
using System;
using System.Xml;

/// <summary>
/// Summary description for XMLMethods.
/// </summary>
public class XMLMethods {

/// <summary>
/// Creates a new instance of XMLMethods
/// </summary>
public XMLMethods() {
}
public string BuildSendXML(String id,String message, String
destination) {

StringWriter sw = new StringWriter();
XmlTextWriter SMSwriter = new XmlTextWriter(sw);

try
{
SMSwriter.Formatting = Formatting.Indented;
SMSwriter.Indentation= 6;
SMSwriter.Namespaces = false;

//SMSwriter.WriteStartDocument(); //outputs beginning xml
tag

SMSwriter.WriteStartElement("", "SMSBatchFile", "");

SMSwriter.WriteStartElement("", "SMSMessage", "");

SMSwriter.WriteStartElement("", "MessageID", "");
SMSwriter.WriteString(id);
SMSwriter.WriteEndElement();

SMSwriter.WriteStartElement("", "MessageText", "");
SMSwriter.WriteString(message);
SMSwriter.WriteEndElement();

SMSwriter.WriteStartElement("", "Destination", "");
SMSwriter.WriteString(destination);
SMSwriter.WriteEndElement();
SMSwriter.WriteEndElement(); //close smsmessage

SMSwriter.WriteEndElement(); //close smsbatchfile

SMSwriter.Flush();
sw.Close();

}
catch(Exception e)
{
//return "Exception: {0}"+ e;
Console.WriteLine("Exception: {0}", e.ToString());
}
finally
{
if (SMSwriter != null)
{
SMSwriter.Close();
}
}

return sw.ToString();

}

public static void Main(string[] args){

//Test BuildSendXML() method
//XMLMethods xm = new XMLMethods();
//String outTxt = xm.BuildSendXML("7","Tickets please","02342375");

//Console.WriteLine(outTxt);


}
}
}


"Marvin Smit" wrote:
Hi,

I also do not see any reason for the 0x00 to show up. There are a few
things that spring to my mind;

- I'm not clear on the String->Byte[]->String conversion code you
provided at the bottom of your post. Is this code you used to check or
part of the implementation you are using?
WebServices work with XML 1.0 + Namespaces, so if you're not using the
XmlSerializer's, the easiest way to deal with this is either a
DOMDocument or A Streaming XML API (XmlWriter).

Can you post the code that "builds & posts the XML message" to the
webservice?

Hope this helps,

Marvin Smit.
On Wed, 26 Oct 2005 22:49:57 -0500, jeremiah johnson
<na*******@gmail.com> wrote:
Well, nulls don't show up when you look at raw text, they're usually
encoded safely in a string so they don't show up when you look at them.
i could be wrong about that, though, its been a long time since i've
fiddled with nulls in text.

if you copy/pasted that string, i'd type it in by hand and try again.
can't get a null in that way.

jeremiah

jasn wrote:
Hello

I am getting the following error message when I try and send an XML sting to
a web service, I read somewhere that most web services prefer ascii and some
throw errors when using unicode so I have changed the encoding but still cant
get rid of the error.

System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
reader) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters) at
SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in
C:\temp\SMS\Authenticate.aspx:line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile><SMSMessage><MessageID>1</MessageID><MessageText>test</MessageText><Destination>40123123</Destination></SMSMessage></SMSBatchFile>";
Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

Has anyone encountered this?

Nov 23 '05 #5
Hi,

thanks for the additional info;

before diving in deeper, i have a question;

Is there any reason for you "not to use a generated proxy"?

Marvin Smit
On Thu, 27 Oct 2005 01:13:01 -0700, "jasn"
<ja**@discussions.microsoft.com> wrote:
Thanks for your response.

Ive tried with and without the String->Byte[]->String conversion and tried
using XMLTextWriter to build the string but this still causes problems.

This is my aspx page:-
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="XMLMethods" %>
<%@ import Namespace="SMSservices" %>
<%@ import Namespace="Authenticate" %>
<script runat="server">

// Insert page code here

SMSAuthentication oSec = new SMSAuthentication();
SMSServices oClient = new SMSServices();
XMLMethods xm = new XMLMethods();

string Username = "test";
string Password = "test";
string messageStr = "";
string messageStatus = "";
string returnKey = "";
string strXML = "";
string Key;
string sXMLRet = "Key";
string proxy = "http://hmt-pxy-2.test.com:8080";

protected void Page_Load(Object Src, EventArgs E)
{
//Authenticate with proxy using default or my login info
if(!"".Equals(proxy))
{
WebProxy proxyObject = new WebProxy(proxy);

// Disable proxy use when the host is local.
proxyObject.BypassProxyOnLocal = true;

//Set proxy Credentials to authenticate on server
//proxyObject.Credentials =
System.Net.CredentialCache.DefaultCredentials;
proxyObject.Credentials = new NetworkCredential("test",
"test", "test");

// HTTP requests use this proxy information.
GlobalProxySelection.Select = proxyObject;

}

// Create Message XML string
messageStr = xm.BuildSendXML("1","Snippets please","44773423432");

try {
//strXML = messageStr

Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

}
catch(Exception e) {
sXMLRet = "<p>ERROR: XML String parse: Please contact
test</p><p>"+e+"</p>";
}

//'Login to obtain valid key
try {
oSec.clientLogin(Username,Password,ref Key);
}
catch(Exception e) {
sXMLRet = "<p>ERROR: Login Failed: Please contact
test</p><p>"+e+"</p>";
}

if (Key != null)
{
try {
returnKey = oClient.sendSMSsender(strXML, "44773423432", Key);
try {

sXMLRet =
oClient.getBatchMessageStatus(messageStatus,Key );

} catch(Exception e){
sXMLRet = "ERROR: Get Message Status Error<br>please
contact test<BR>"+e;
}
}
catch(Exception e){
sXMLRet = "ERROR: Send Message Error<br>please contact
test<br><br>"+e;
}
}

}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<p>
<%=returnKey%>
</p>
<p>
<%=strXML%>
</p>
<p>
<%=sXMLRet%>
</p>
</form>
</body>
</html>
and this is the class that I use to build the XML:-

// XMLMethods.cs
//

namespace XMLMethods {
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
using System;
using System.Xml;

/// <summary>
/// Summary description for XMLMethods.
/// </summary>
public class XMLMethods {

/// <summary>
/// Creates a new instance of XMLMethods
/// </summary>
public XMLMethods() {
}
public string BuildSendXML(String id,String message, String
destination) {

StringWriter sw = new StringWriter();
XmlTextWriter SMSwriter = new XmlTextWriter(sw);

try
{
SMSwriter.Formatting = Formatting.Indented;
SMSwriter.Indentation= 6;
SMSwriter.Namespaces = false;

//SMSwriter.WriteStartDocument(); //outputs beginning xml
tag

SMSwriter.WriteStartElement("", "SMSBatchFile", "");

SMSwriter.WriteStartElement("", "SMSMessage", "");

SMSwriter.WriteStartElement("", "MessageID", "");
SMSwriter.WriteString(id);
SMSwriter.WriteEndElement();

SMSwriter.WriteStartElement("", "MessageText", "");
SMSwriter.WriteString(message);
SMSwriter.WriteEndElement();

SMSwriter.WriteStartElement("", "Destination", "");
SMSwriter.WriteString(destination);
SMSwriter.WriteEndElement();
SMSwriter.WriteEndElement(); //close smsmessage

SMSwriter.WriteEndElement(); //close smsbatchfile

SMSwriter.Flush();
sw.Close();

}
catch(Exception e)
{
//return "Exception: {0}"+ e;
Console.WriteLine("Exception: {0}", e.ToString());
}
finally
{
if (SMSwriter != null)
{
SMSwriter.Close();
}
}

return sw.ToString();

}

public static void Main(string[] args){

//Test BuildSendXML() method
//XMLMethods xm = new XMLMethods();
//String outTxt = xm.BuildSendXML("7","Tickets please","02342375");

//Console.WriteLine(outTxt);


}
}
}


"Marvin Smit" wrote:
Hi,

I also do not see any reason for the 0x00 to show up. There are a few
things that spring to my mind;

- I'm not clear on the String->Byte[]->String conversion code you
provided at the bottom of your post. Is this code you used to check or
part of the implementation you are using?
WebServices work with XML 1.0 + Namespaces, so if you're not using the
XmlSerializer's, the easiest way to deal with this is either a
DOMDocument or A Streaming XML API (XmlWriter).

Can you post the code that "builds & posts the XML message" to the
webservice?

Hope this helps,

Marvin Smit.
On Wed, 26 Oct 2005 22:49:57 -0500, jeremiah johnson
<na*******@gmail.com> wrote:
>Well, nulls don't show up when you look at raw text, they're usually
>encoded safely in a string so they don't show up when you look at them.
> i could be wrong about that, though, its been a long time since i've
>fiddled with nulls in text.
>
>if you copy/pasted that string, i'd type it in by hand and try again.
>can't get a null in that way.
>
>jeremiah
>
>jasn wrote:
>> Hello
>>
>> I am getting the following error message when I try and send an XML sting to
>> a web service, I read somewhere that most web services prefer ascii and some
>> throw errors when using unicode so I have changed the encoding but still cant
>> get rid of the error.
>>
>> System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
>> character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
>> System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
>> System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
>> at
>> System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
>> reader) at
>> System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
>> message, WebResponse response, Stream responseStream, Boolean asyncCall) at
>> System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
>> methodName, Object[] parameters) at
>> SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
>> Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in
>> C:\temp\SMS\Authenticate.aspx:line 99
>>
>> As you can see below there is no null, in my string The string that I use is
>> messageStr =
>> "<SMSBatchFile><SMSMessage><MessageID>1</MessageID><MessageText>test</MessageText><Destination>40123123</Destination></SMSMessage></SMSBatchFile>";
>>
>>
>> Encoding ascii = Encoding.ASCII;
>> Byte[] encodedBytes = ascii.GetBytes(messageStr);
>> strXML = ascii.GetString(encodedBytes);
>>
>> Has anyone encountered this?


Nov 23 '05 #6
Hello
I had a similar problem in one of my web services. it is a problem of the
data in the xml. Errors of this type are hard to debug. I did a replace after
a I receive a response from the web service just to remove any unrecognizable
characters.
Not an efficient solution but works.
Another thing, can you load your request string into an xml document properly?
Thanks
Deepak

"Marvin Smit" wrote:
Hi,

thanks for the additional info;

before diving in deeper, i have a question;

Is there any reason for you "not to use a generated proxy"?

Marvin Smit
On Thu, 27 Oct 2005 01:13:01 -0700, "jasn"
<ja**@discussions.microsoft.com> wrote:
Thanks for your response.

Ive tried with and without the String->Byte[]->String conversion and tried
using XMLTextWriter to build the string but this still causes problems.

This is my aspx page:-
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="XMLMethods" %>
<%@ import Namespace="SMSservices" %>
<%@ import Namespace="Authenticate" %>
<script runat="server">

// Insert page code here

SMSAuthentication oSec = new SMSAuthentication();
SMSServices oClient = new SMSServices();
XMLMethods xm = new XMLMethods();

string Username = "test";
string Password = "test";
string messageStr = "";
string messageStatus = "";
string returnKey = "";
string strXML = "";
string Key;
string sXMLRet = "Key";
string proxy = "http://hmt-pxy-2.test.com:8080";

protected void Page_Load(Object Src, EventArgs E)
{
//Authenticate with proxy using default or my login info
if(!"".Equals(proxy))
{
WebProxy proxyObject = new WebProxy(proxy);

// Disable proxy use when the host is local.
proxyObject.BypassProxyOnLocal = true;

//Set proxy Credentials to authenticate on server
//proxyObject.Credentials =
System.Net.CredentialCache.DefaultCredentials;
proxyObject.Credentials = new NetworkCredential("test",
"test", "test");

// HTTP requests use this proxy information.
GlobalProxySelection.Select = proxyObject;

}

// Create Message XML string
messageStr = xm.BuildSendXML("1","Snippets please","44773423432");

try {
//strXML = messageStr

Encoding ascii = Encoding.ASCII;
Byte[] encodedBytes = ascii.GetBytes(messageStr);
strXML = ascii.GetString(encodedBytes);

}
catch(Exception e) {
sXMLRet = "<p>ERROR: XML String parse: Please contact
test</p><p>"+e+"</p>";
}

//'Login to obtain valid key
try {
oSec.clientLogin(Username,Password,ref Key);
}
catch(Exception e) {
sXMLRet = "<p>ERROR: Login Failed: Please contact
test</p><p>"+e+"</p>";
}

if (Key != null)
{
try {
returnKey = oClient.sendSMSsender(strXML, "44773423432", Key);
try {

sXMLRet =
oClient.getBatchMessageStatus(messageStatus,Key );

} catch(Exception e){
sXMLRet = "ERROR: Get Message Status Error<br>please
contact test<BR>"+e;
}
}
catch(Exception e){
sXMLRet = "ERROR: Send Message Error<br>please contact
test<br><br>"+e;
}
}

}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<p>
<%=returnKey%>
</p>
<p>
<%=strXML%>
</p>
<p>
<%=sXMLRet%>
</p>
</form>
</body>
</html>
and this is the class that I use to build the XML:-

// XMLMethods.cs
//

namespace XMLMethods {
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
using System;
using System.Xml;

/// <summary>
/// Summary description for XMLMethods.
/// </summary>
public class XMLMethods {

/// <summary>
/// Creates a new instance of XMLMethods
/// </summary>
public XMLMethods() {
}
public string BuildSendXML(String id,String message, String
destination) {

StringWriter sw = new StringWriter();
XmlTextWriter SMSwriter = new XmlTextWriter(sw);

try
{
SMSwriter.Formatting = Formatting.Indented;
SMSwriter.Indentation= 6;
SMSwriter.Namespaces = false;

//SMSwriter.WriteStartDocument(); //outputs beginning xml
tag

SMSwriter.WriteStartElement("", "SMSBatchFile", "");

SMSwriter.WriteStartElement("", "SMSMessage", "");

SMSwriter.WriteStartElement("", "MessageID", "");
SMSwriter.WriteString(id);
SMSwriter.WriteEndElement();

SMSwriter.WriteStartElement("", "MessageText", "");
SMSwriter.WriteString(message);
SMSwriter.WriteEndElement();

SMSwriter.WriteStartElement("", "Destination", "");
SMSwriter.WriteString(destination);
SMSwriter.WriteEndElement();
SMSwriter.WriteEndElement(); //close smsmessage

SMSwriter.WriteEndElement(); //close smsbatchfile

SMSwriter.Flush();
sw.Close();

}
catch(Exception e)
{
//return "Exception: {0}"+ e;
Console.WriteLine("Exception: {0}", e.ToString());
}
finally
{
if (SMSwriter != null)
{
SMSwriter.Close();
}
}

return sw.ToString();

}

public static void Main(string[] args){

//Test BuildSendXML() method
//XMLMethods xm = new XMLMethods();
//String outTxt = xm.BuildSendXML("7","Tickets please","02342375");

//Console.WriteLine(outTxt);


}
}
}


"Marvin Smit" wrote:
Hi,

I also do not see any reason for the 0x00 to show up. There are a few
things that spring to my mind;

- I'm not clear on the String->Byte[]->String conversion code you
provided at the bottom of your post. Is this code you used to check or
part of the implementation you are using?
WebServices work with XML 1.0 + Namespaces, so if you're not using the
XmlSerializer's, the easiest way to deal with this is either a
DOMDocument or A Streaming XML API (XmlWriter).

Can you post the code that "builds & posts the XML message" to the
webservice?

Hope this helps,

Marvin Smit.
On Wed, 26 Oct 2005 22:49:57 -0500, jeremiah johnson
<na*******@gmail.com> wrote:

>Well, nulls don't show up when you look at raw text, they're usually
>encoded safely in a string so they don't show up when you look at them.
> i could be wrong about that, though, its been a long time since i've
>fiddled with nulls in text.
>
>if you copy/pasted that string, i'd type it in by hand and try again.
>can't get a null in that way.
>
>jeremiah
>
>jasn wrote:
>> Hello
>>
>> I am getting the following error message when I try and send an XML sting to
>> a web service, I read somewhere that most web services prefer ascii and some
>> throw errors when using unicode so I have changed the encoding but still cant
>> get rid of the error.
>>
>> System.Xml.XmlException: '', hexadecimal value 0x00, is an invalid
>> character. Line 6, position 124. at System.Xml.XmlScanner.ScanHexEntity() at
>> System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities() at
>> System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
>> at
>> System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadSoapException(XmlReader
>> reader) at
>> System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
>> message, WebResponse response, Stream responseStream, Boolean asyncCall) at
>> System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
>> methodName, Object[] parameters) at
>> SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
>> Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Barry Young | last post by:
I am using the following code to insert a row in an Oracle Database. strConnection = "Provider=OraOLEDB.Oracle;Data Source=MYDATABASE;User Id=SYSTEM;Password=******" Dim strMessage As String ...
4
by: Supertzar | last post by:
Hi, I'm trying to use MapPath on a folder named with a comma in it: xmldoc.load Server.MapPath(Request.QueryString("fname")) where the querysting is something like "fname=this, that/this,...
2
by: Anna Carr | last post by:
I had a project which was working until this morning and I keep getting the following error. Does anyone know what has happened and how I can fix it?? error message - There is an invalid...
0
by: DCC700 | last post by:
After converting a web application to 2005, I am receiving an invalid character error when I change the value in a dropdown list. The dropdown list is set to postback on selected index changed and...
3
by: Middletree | last post by:
Teaching myself ASP.NET, using Microsoft Press book called ASP.NET 2.0 by George Shepherd. Ch. 2, it says to type the following code: <%@ Page Language="C#" %> <html>
1
by: DCC700 | last post by:
After upgrading a web application from VS 2003 to 2005 there is a page where any control event that should cause a postback instead generates an Invalid character error on the page. For example a...
4
by: Arpan | last post by:
I am working on Win2K Pro. Due to some problems in IIS5.0, I had to uninstall & re-install IIS. After re-installing IIS, when I try to run any ASPX page (all my ASPX pages reside in...
1
by: qbp90x5lb | last post by:
I'm using an XSLT transform to output the element value contents from a simple XML file into a new .TXT file. Everything works fine except for certain XML files, when calling msxsl with the .xslt, I...
1
by: Anthony Herrera | last post by:
CREATE TABLE CP_INTFDC (ID_ACQ_IIC number(11,0) not null, ID_FWD_IIC number(11,0) not null, ID_INCOMING_TIMER number(6,0) DEFAULT 600 NOT NULL, ID_OUTGOING_TIMER ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.