名称不能以c#中的''字符,十六进制值0x20开头使用xml String [duplicate]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了名称不能以c#中的''字符,十六进制值0x20开头使用xml String [duplicate]相关的知识,希望对你有一定的参考价值。
这个问题在这里已有答案:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Net;
using System.IO;
namespace SOAPServices
{
class Program
{
static void Main(string[] args)
{
CallWebService();
}
public static void CallWebService()
{
var _url = "http://exampleurl.svc";
var _action = "http://examplemethod";
XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
// begin async call to web request.
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
asyncResult.AsyncWaitHandle.WaitOne();
// get the response from the completed web request.
string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
Console.Write(soapResult);
}
}
private static HttpWebRequest CreateWebRequest(string url, string action)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset="utf-8"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
private static XmlDocument CreateSoapEnvelope()
{
XmlDocument soapEnvelopeDocument = new XmlDocument();
soapEnvelopeDocument.LoadXml(@"<?xml version=""1.0"" encoding=""UTF - 8""?>
< soapenv:Envelope xmlns:soapenv = ""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ass = ""http://assetrecovery.assurant.com/"" xmlns: ass1 = ""http://schemas.datacontract.org/2004/07/AssetRecovery_Service.Entities"" xmlns: tem = ""http://tempuri.org/"" >
< soapenv:Header >
< ass:AuthenticationHeader >
< !--Optional:-->
< ass:Password > Testing </ ass:Password >
< !--Optional:-->
< ass:UserName > Testing </ ass:UserName >
< !--Optional:-->
< ass:VersionNumber > 3 </ ass:VersionNumber >
</ ass:AuthenticationHeader >
</ soapenv:Header >
< soapenv:Body >
< tem:Set_SubmitClaim >
< !--Optional:-->
< tem:request >
< ass1:AccountID > 987605589 </ ass1:AccountID >
< ass1:City > WAYNE </ ass1:City >
< ass1:ClaimantContactNumber > 9329496466 </ ass1:ClaimantContactNumber >
< ass1:ClaimantFirstName > BILL </ ass1:ClaimantFirstName >
< ass1:ClaimantLastName > SMITH </ ass1:ClaimantLastName >
< ass1:DateOfLoss > 02 / 20 / 2018 </ ass1:DateOfLoss >
< !--Optional:-->
< ass1:EmailAddress > test@test.com </ ass1:EmailAddress >
< ass1:InsuredFirstName > BILL </ ass1:InsuredFirstName >
< ass1:InsuredLastName > SMITH </ ass1:InsuredLastName >
< ass1:LossDescription > DROPPED IN THE MALL TEST </ ass1:LossDescription >
< ass1:LossType > PHYSICAL_DAMAGE </ ass1:LossType >
< ass1:Manufacturer > APPLE </ ass1:Manufacturer >
< ass1:Model > IPHONE 6 PLUS 16GB SPACE GRAY TMO </ ass1:Model >
< !--Optional:-->
< ass1:PhoneProblem > CRACKET SCREEN / DISPLAY </ ass1:PhoneProblem >
< ass1:Program > JUMP </ ass1:Program >
< ass1:RepID > 7578 </ ass1:RepID >
< ass1:SKU > MGAX2LL / A </ ass1:SKU >
< ass1:SerialNumber > 105589918105590 </ ass1:SerialNumber >
< ass1:State > PA </ ass1:State >
< ass1:StreetAddress1 > 676 E SWEDESFORD RD </ ass1:StreetAddress1 >
< !--Optional:-->
< ass1:StreetAddress2 />
< ass1:SubscriberID > 8080805589 </ ass1:SubscriberID >
< ass1:Zip > 19087 </ ass1:Zip >
</ tem:request >
</ tem:Set_SubmitClaim >
</ soapenv:Body >
</ soapenv:Envelope > ");
return soapEnvelopeDocument;
}
private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
}
}
}
通过执行上面的代码我得到xml错误,如名称不能以''字符,十六进制值0x20开头。 xml字符串可能导致问题,我无法追踪确切的错误在哪里。我在谷歌找到了一些答案,但发现没有运气请任何人可以帮我这个我是C#的新手
答案
正如您对问题的评论中所指出的,错误消息的含义正是它所说的:在开始或结束标记中的名称之前不允许使用空格。
以上是关于名称不能以c#中的''字符,十六进制值0x20开头使用xml String [duplicate]的主要内容,如果未能解决你的问题,请参考以下文章
C语言:怎么将十六进制字符串转换成二进制字符串,谁帮我写个函数