C# - System.Xml.XmlException:'@'字符错误

时间:2012-05-22 05:21:12

标签: c# xml error-handling character

我遇到了这段代码的问题。

        XMLParameter param1 = new XMLParameter();
        TabletWebService service1 = ModuleName.MainWebService();
        param1.Add(ModuleName.AuthorityKey);
        param1.Add(ModuleName.UserID);
        param1.Add("@iJobID", jobID);
        byte[] buffer1 = service1.GetPreviousJobs(param1.ToString(), false);

此代码使用存储的MS SQL过程,如下所示:

create procedure [dbo].[GetPreviousJob]
@iJobID int
as set nocount on

select 
pj.*, 
    j.dValuationDate
from 
    PreviousJobs pj,
    Jobs j
where pj.iAttachedID = @iJobID
    and j.iJobID = pj.iJobID

所以你可以看到我需要使用“@iJobID”

我收到的错误是谷歌中常见的错误,但是我仍然无法找到回复。

ERROR:

System.Web.Services.Protocols.SoapException: Server was unable to process request.
---> System.Xml.XmlException: Name cannot begin with the '@' character, hexadecimal value 0x40. Line 5, position 6.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos)
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(TextReader txtReader)
at WBP.Windows.XMLParameter.Load(String sXML) in C:\xpressCentral\WBP.Windows\XMLParameter.cs:line 98
at WBP.Windows.XMLParameter..ctor(String sXML) in C:\xpressCentral\WBP.Windows\XMLParameter.cs:line 41
at WirelessConnector.GetPreviousJobs(String sParams) in c:\xpressCentral\WBP.WirelessConnector\App_Code\WBP.WirelessConnector.cs:line 234
--- End of inner exception stack trace ---

我可以告诉他们,@ char导致了这个问题,但为了正确地解决SQL中的存储过程,我必须包括这个。

我应该尝试捕捉异常吗?

System.Web.Services.Protocols.SoapException:  ???

任何想法???

谢谢AC

0 个答案:

没有答案