471,582 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 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 31661
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Supertzar | last post: by
2 posts views Thread by Anna Carr | last post: by
4 posts views Thread by Arpan | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by

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.