473,231 Members | 1,904 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,231 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 31916
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 ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.