473,606 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.XmlE xception: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
reader) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters) at
SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
Key) at ASP.Authenticat e_aspx.Page_Loa d(Object Src, EventArgs E) in
C:\temp\SMS\Aut henticate.aspx: line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile> <SMSMessage><Me ssageID>1</MessageID><Mess ageText>test</MessageText><De stination>40123 123</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 31980
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.XmlE xception: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
reader) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters) at
SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
Key) at ASP.Authenticat e_aspx.Page_Loa d(Object Src, EventArgs E) in
C:\temp\SMS\Aut henticate.aspx: line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile> <SMSMessage><Me ssageID>1</MessageID><Mess ageText>test</MessageText><De stination>40123 123</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.XmlE xception: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
reader) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters) at
SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
Key) at ASP.Authenticat e_aspx.Page_Loa d(Object Src, EventArgs E) in
C:\temp\SMS\Aut henticate.aspx: line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile> <SMSMessage><Me ssageID>1</MessageID><Mess ageText>test</MessageText><De stination>40123 123</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*******@gmai l.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.XmlE xception: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
reader) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters) at
SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
Key) at ASP.Authenticat e_aspx.Page_Loa d(Object Src, EventArgs E) in
C:\temp\SMS\Aut henticate.aspx: line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile> <SMSMessage><Me ssageID>1</MessageID><Mess ageText>test</MessageText><De stination>40123 123</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="Syst em" %>
<%@ import Namespace="Syst em.IO" %>
<%@ import Namespace="Syst em.Text.Regular Expressions" %>
<%@ import Namespace="Syst em.Xml" %>
<%@ import Namespace="Syst em.Net" %>
<%@ import Namespace="XMLM ethods" %>
<%@ import Namespace="SMSs ervices" %>
<%@ import Namespace="Auth enticate" %>
<script runat="server">

// Insert page code here

SMSAuthenticati on oSec = new SMSAuthenticati on();
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(Objec t Src, EventArgs E)
{
//Authenticate with proxy using default or my login info
if(!"".Equals(p roxy))
{
WebProxy proxyObject = new WebProxy(proxy) ;

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

//Set proxy Credentials to authenticate on server
//proxyObject.Cre dentials =
System.Net.Cred entialCache.Def aultCredentials ;
proxyObject.Cre dentials = new NetworkCredenti al("test",
"test", "test");

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

}

// Create Message XML string
messageStr = xm.BuildSendXML ("1","Snippe ts please","447734 23432");

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.clientLogi n(Username,Pass word,ref Key);
}
catch(Exception e) {
sXMLRet = "<p>ERROR: Login Failed: Please contact
test</p><p>"+e+"</p>";
}

if (Key != null)
{
try {
returnKey = oClient.sendSMS sender(strXML, "4477342343 2", Key);
try {

sXMLRet =
oClient.getBatc hMessageStatus( messageStatus,K ey);

} 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.Reg ularExpressions ;
using System.Globaliz ation;
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(St ring id,String message, String
destination) {

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

try
{
SMSwriter.Forma tting = Formatting.Inde nted;
SMSwriter.Inden tation= 6;
SMSwriter.Names paces = false;

//SMSwriter.Write StartDocument() ; //outputs beginning xml
tag

SMSwriter.Write StartElement("" , "SMSBatchFi le", "");

SMSwriter.Write StartElement("" , "SMSMessage ", "");

SMSwriter.Write StartElement("" , "MessageID" , "");
SMSwriter.Write String(id);
SMSwriter.Write EndElement();

SMSwriter.Write StartElement("" , "MessageTex t", "");
SMSwriter.Write String(message) ;
SMSwriter.Write EndElement();

SMSwriter.Write StartElement("" , "Destinatio n", "");
SMSwriter.Write String(destinat ion);
SMSwriter.Write EndElement();
SMSwriter.Write EndElement(); //close smsmessage

SMSwriter.Write EndElement(); //close smsbatchfile

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

}
catch(Exception e)
{
//return "Exception: {0}"+ e;
Console.WriteLi ne("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","Ticket s please","023423 75");

//Console.WriteLi ne(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*******@gmai l.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.XmlE xception: '', hexadecimal value 0x00, is an invalid
character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
reader) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters) at
SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
Key) at ASP.Authenticat e_aspx.Page_Loa d(Object Src, EventArgs E) in
C:\temp\SMS\Aut henticate.aspx: line 99

As you can see below there is no null, in my string The string that I use is
messageStr =
"<SMSBatchFile> <SMSMessage><Me ssageID>1</MessageID><Mess ageText>test</MessageText><De stination>40123 123</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**@discussio ns.microsoft.co m> 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="Syst em" %>
<%@ import Namespace="Syst em.IO" %>
<%@ import Namespace="Syst em.Text.Regular Expressions" %>
<%@ import Namespace="Syst em.Xml" %>
<%@ import Namespace="Syst em.Net" %>
<%@ import Namespace="XMLM ethods" %>
<%@ import Namespace="SMSs ervices" %>
<%@ import Namespace="Auth enticate" %>
<script runat="server">

// Insert page code here

SMSAuthenticati on oSec = new SMSAuthenticati on();
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(Objec t Src, EventArgs E)
{
//Authenticate with proxy using default or my login info
if(!"".Equals(p roxy))
{
WebProxy proxyObject = new WebProxy(proxy) ;

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

//Set proxy Credentials to authenticate on server
//proxyObject.Cre dentials =
System.Net.Cre dentialCache.De faultCredential s;
proxyObject.Cre dentials = new NetworkCredenti al("test",
"test", "test");

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

}

// Create Message XML string
messageStr = xm.BuildSendXML ("1","Snippe ts please","447734 23432");

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.clientLogi n(Username,Pass word,ref Key);
}
catch(Exception e) {
sXMLRet = "<p>ERROR: Login Failed: Please contact
test</p><p>"+e+"</p>";
}

if (Key != null)
{
try {
returnKey = oClient.sendSMS sender(strXML, "4477342343 2", Key);
try {

sXMLRet =
oClient.getBat chMessageStatus (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.Reg ularExpressions ;
using System.Globaliz ation;
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(St ring id,String message, String
destination) {

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

try
{
SMSwriter.Forma tting = Formatting.Inde nted;
SMSwriter.Inden tation= 6;
SMSwriter.Names paces = false;

//SMSwriter.Write StartDocument() ; //outputs beginning xml
tag

SMSwriter.Write StartElement("" , "SMSBatchFi le", "");

SMSwriter.Write StartElement("" , "SMSMessage ", "");

SMSwriter.Write StartElement("" , "MessageID" , "");
SMSwriter.Write String(id);
SMSwriter.Write EndElement();

SMSwriter.Write StartElement("" , "MessageTex t", "");
SMSwriter.Write String(message) ;
SMSwriter.Write EndElement();

SMSwriter.Write StartElement("" , "Destinatio n", "");
SMSwriter.Write String(destinat ion);
SMSwriter.Write EndElement();
SMSwriter.Write EndElement(); //close smsmessage

SMSwriter.Write EndElement(); //close smsbatchfile

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

}
catch(Exception e)
{
//return "Exception: {0}"+ e;
Console.WriteLi ne("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","Ticket s please","023423 75");

//Console.WriteLi ne(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*******@gmai l.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.XmlE xception: '', hexadecimal value 0x00, is an invalid
>> character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
>> System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
>> System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
>> at
>> System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
>> reader) at
>> System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
>> message, WebResponse response, Stream responseStream, Boolean asyncCall) at
>> System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
>> methodName, Object[] parameters) at
>> SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
>> Key) at ASP.Authenticat e_aspx.Page_Loa d(Object Src, EventArgs E) in
>> C:\temp\SMS\Aut henticate.aspx: line 99
>>
>> As you can see below there is no null, in my string The string that I use is
>> messageStr =
>> "<SMSBatchFile> <SMSMessage><Me ssageID>1</MessageID><Mess ageText>test</MessageText><De stination>40123 123</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**@discussio ns.microsoft.co m> 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="Syst em" %>
<%@ import Namespace="Syst em.IO" %>
<%@ import Namespace="Syst em.Text.Regular Expressions" %>
<%@ import Namespace="Syst em.Xml" %>
<%@ import Namespace="Syst em.Net" %>
<%@ import Namespace="XMLM ethods" %>
<%@ import Namespace="SMSs ervices" %>
<%@ import Namespace="Auth enticate" %>
<script runat="server">

// Insert page code here

SMSAuthenticati on oSec = new SMSAuthenticati on();
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(Objec t Src, EventArgs E)
{
//Authenticate with proxy using default or my login info
if(!"".Equals(p roxy))
{
WebProxy proxyObject = new WebProxy(proxy) ;

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

//Set proxy Credentials to authenticate on server
//proxyObject.Cre dentials =
System.Net.Cre dentialCache.De faultCredential s;
proxyObject.Cre dentials = new NetworkCredenti al("test",
"test", "test");

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

}

// Create Message XML string
messageStr = xm.BuildSendXML ("1","Snippe ts please","447734 23432");

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.clientLogi n(Username,Pass word,ref Key);
}
catch(Exception e) {
sXMLRet = "<p>ERROR: Login Failed: Please contact
test</p><p>"+e+"</p>";
}

if (Key != null)
{
try {
returnKey = oClient.sendSMS sender(strXML, "4477342343 2", Key);
try {

sXMLRet =
oClient.getBat chMessageStatus (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.Reg ularExpressions ;
using System.Globaliz ation;
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(St ring id,String message, String
destination) {

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

try
{
SMSwriter.Forma tting = Formatting.Inde nted;
SMSwriter.Inden tation= 6;
SMSwriter.Names paces = false;

//SMSwriter.Write StartDocument() ; //outputs beginning xml
tag

SMSwriter.Write StartElement("" , "SMSBatchFi le", "");

SMSwriter.Write StartElement("" , "SMSMessage ", "");

SMSwriter.Write StartElement("" , "MessageID" , "");
SMSwriter.Write String(id);
SMSwriter.Write EndElement();

SMSwriter.Write StartElement("" , "MessageTex t", "");
SMSwriter.Write String(message) ;
SMSwriter.Write EndElement();

SMSwriter.Write StartElement("" , "Destinatio n", "");
SMSwriter.Write String(destinat ion);
SMSwriter.Write EndElement();
SMSwriter.Write EndElement(); //close smsmessage

SMSwriter.Write EndElement(); //close smsbatchfile

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

}
catch(Exception e)
{
//return "Exception: {0}"+ e;
Console.WriteLi ne("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","Ticket s please","023423 75");

//Console.WriteLi ne(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*******@gmai l.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.XmlE xception: '', hexadecimal value 0x00, is an invalid
>> character. Line 6, position 124. at System.Xml.XmlS canner.ScanHexE ntity() at
>> System.Xml.XmlT extReader.Parse BeginTagExpandC harEntities() at
>> System.Xml.XmlT extReader.Read( ) at System.Xml.XmlR eader.ReadEleme ntString()
>> at
>> System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadSoa pException(XmlR eader
>> reader) at
>> System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage
>> message, WebResponse response, Stream responseStream, Boolean asyncCall) at
>> System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
>> methodName, Object[] parameters) at
>> SMSservices.SMS Services.sendSM Ssender(String Messages, String Sender, String
>> Key) at ASP.Authenticat e_aspx.Page_Loa d(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
12631
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 Dim objConnection As New OleDb.OleDbConnection(strConnection) Dim objCommand As OleDb.OleDbCommand
4
5603
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, that.xml". I'm sure it's the comma, because if I remove it and rename the file and folder, everything works. I believe that a comma is a valid character in a folder or filename,
2
8448
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 character in the given encoding. Line 1, position 1. line highlighted in red = this.LoadLayout(this.GetType (), "Causeway_Reports.ForensicEvidenceDetails.rpx");
0
1385
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 perform some actions. The postback is not happening due to this error on the page. All the dropdown lists on this page cause this error, but I use dropdowns on many other pages that do not have any problems. Any ideas??? *** Sent via...
3
4138
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
2710
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 drop down list is set to AutoPostBack, and for OnSelectedIndexChanged should update the values of other drop down lists. This page works fine in VS 2003, and the other pages with similar controls are posting back fine in 2005. Has anyone else...
4
4704
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 C:\Inetpub\wwwroot\ASPX folder) by typing the following URL in IE6.0 http://myserver/ASPX/MyPage.aspx the following error gets generated: A name was started with an invalid character. Error processing resource
1
3807
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 get the following error: Code: 0xc00ce504 File: ...... Line: ... Column: ... A name was started with an invalid character. The error refers to the '<' found in the string "<20" from my example xml file below (a).
1
1983
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 number(6,0) DEFAULT 30 NOT NULL, ID_STDIN_IND varchar2(1) DEFAULT 2 NOT NULL, ); I am having a problem invalid indentifier when i have a default value and also have a not null set it during creation. Please help.
0
8031
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7962
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8443
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8107
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8315
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5467
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3945
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2452
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1309
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.