hexadecimal value 0x00, is an invalid character error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jasn

    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?
  • jeremiah johnson

    #2
    Re: hexadecimal value 0x00, is an invalid character error

    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:[color=blue]
    > 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?[/color]

    Comment

    • jasn

      #3
      Re: hexadecimal value 0x00, is an invalid character error

      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:
      [color=blue]
      > 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:[color=green]
      > > 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?[/color]
      >[/color]

      Comment

      • Marvin Smit

        #4
        Re: hexadecimal value 0x00, is an invalid character error

        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
        <naikrovek@gmai l.com> wrote:
        [color=blue]
        >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:[color=green]
        >> 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?[/color][/color]

        Comment

        • jasn

          #5
          Re: hexadecimal value 0x00, is an invalid character error

          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:
          [color=blue]
          > 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
          > <naikrovek@gmai l.com> wrote:
          >[color=green]
          > >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:[color=darkred]
          > >> 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?[/color][/color]
          >[/color]

          Comment

          • Marvin Smit

            #6
            Re: hexadecimal value 0x00, is an invalid character error

            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"
            <jasn@discussio ns.microsoft.co m> wrote:
            [color=blue]
            >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:
            >[color=green]
            >> 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
            >> <naikrovek@gmai l.com> wrote:
            >>[color=darkred]
            >> >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?[/color]
            >>[/color][/color]

            Comment

            • Deepak

              #7
              Re: hexadecimal value 0x00, is an invalid character error

              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:
              [color=blue]
              > 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"
              > <jasn@discussio ns.microsoft.co m> wrote:
              >[color=green]
              > >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:
              > >[color=darkred]
              > >> 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
              > >> <naikrovek@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[/color][/color][/color]

              Comment

              Working...