Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / October 2005

Tip: Looking for answers? Try searching our database.

hexadecimal value 0x00, is an invalid character error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jasn - 26 Oct 2005 14:06 GMT
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.ParseBeginTagExpandCharEntities() at
System.Xml.XmlTextReader.Read() at System.Xml.XmlReader.ReadElementString()
at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadSoapException(XmlReader
reader) at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall) at
System.Web.Services.Protocols.SoapHttpClientProtocol.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?
jeremiah johnson - 27 Oct 2005 04:49 GMT
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

> Hello
>
[quoted text clipped - 27 lines]
>
> Has anyone encountered this?
jasn - 27 Oct 2005 08:47 GMT
Thats what I originally thought but Ive also tried creating the string using
XmlTextWriter and this still gives me the same error message.

> 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.
[quoted text clipped - 37 lines]
> >
> > Has anyone encountered this?
Marvin Smit - 27 Oct 2005 08:54 GMT
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.

>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.
[quoted text clipped - 37 lines]
>>
>> Has anyone encountered this?
jasn - 27 Oct 2005 09:13 GMT
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);

     

       }
   }
}

> Hi,
>
[quoted text clipped - 56 lines]
> >>
> >> Has anyone encountered this?
Marvin Smit - 27 Oct 2005 14:12 GMT
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

>Thanks for your response.
>
[quoted text clipped - 273 lines]
>> >>
>> >> Has anyone encountered this?
Deepak - 27 Oct 2005 23:16 GMT
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

> Hi,
>
[quoted text clipped - 272 lines]
> >> >> SMSservices.SMSServices.sendSMSsender(String Messages, String Sender, String
> >> >> Key) at ASP.Authenticate_aspx.Page_Load(Object Src, EventArgs E) in

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.