已解决this link
我正在开发一个具有休息模式的wcf服务。现在它位于IIS服务器上。
它有一个可以用帖子调用的方法,它必须接收一个xml数据。
我试图发送这个xml(带有其他参数),但我只得到了deserial错误:
in System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
in System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
in System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
in System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
in System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
这是请求:
retista=0019&hashedStrig=dkfjdkfjd&dati=<ArrayOfWrapClienti xmlns="http://schemas.datacontract.org/2004/07/MultipayOnline" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><WrapClienti><CODRETE>0018</CODRETE><CODICE>20685</CODICE><NOME>A.T.E.R. Azienda Territoriale</NOME><INDIRIZZO>PIAZZA POZZA</INDIRIZZO><CITTA>Verona</CITTA><CAP>37123</CAP><PROV>VR</PROV><CODICEFISCALE>00223640236</CODICEFISCALE><PIVA>223640236</PIVA><EMAIL/><ESPOSIZ_CONTABILE>937,02</ESPOSIZ_CONTABILE><STATO>FALSE</STATO></WrapClienti></ArrayOfWrapClienti>
这是我尝试发送的xml:
<ArrayOfWrapClienti xmlns="http://schemas.datacontract.org/2004/07/aaa" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<WrapClienti>
<CODRETE>1111</CODRETE>
<CODICE>111</CODICE>
<NOME>AAA</NOME>
<INDIRIZZO>PIAZZA</INDIRIZZO>
<CITTA>AAA</CITTA>
<CAP>111</CAP>
<PROV>aa</PROV>
<CODICEFISCALE>111</CODICEFISCALE>
<PIVA>223611140236</PIVA>
<EMAIL/>
<ESPOSIZ_CONTABILE>1111</ESPOSIZ_CONTABILE>
<STATO>FALSE</STATO>
</WrapClienti>
</ArrayOfWrapClienti>
如果单击here,您可以了解我的wcf如何返回xml。我以为我必须发送与其他数据相同的xml,但我得到了deserial错误。
为什么?
如何将xml发送到我的wcf?在此测试阶段,我使用this。
如果我能给你其他有用的信息,请问我,我会在这里写下来。
更新:错误消息的文本显示根级别第1行,第1行有无效数据。如果我放
<?xml version="1.0" encoding="utf-8" ?>
在根级别。
也许有一些遗失的标题?
UPDATE服务器端:
这是我的服务器wcf的配置方式:
[OperationContract]
[WebGet(UriTemplate = "cliente.xml?retista={codret}&cliente={codiceCliente}&H={hashedString}", ResponseFormat = WebMessageFormat.Xml)]
List<WrapClienti> GetClienteXML(string codret, string codiceCliente, string hashedString);
这是被调用的方法:
public GenericResponse SetClientiXML(List<WrapClienti> clienti, string retista, string hashedString)
{
var api = new API();
return api.SetClienti(clienti, retista, hashedString);
}
我可以看到,我没有管理任何xml / json反序列化阶段,它由wcf例程管理。例如,如果我发送一个json列表,它会将其转换为List。这也是我想看到的xml,但我在这个问题的顶部得到错误。
另一个更新:我必须在xml中发送3个参数,所以....这是我的最后一次尝试,我认为它比预先更正确。现在服务器给出了空引用错误:
<?xml version="1.0" encoding="utf-8" ?>
<SetClientiXML
xmlns="http://tempuri.org/">
<XMLRequest>
<ArrayOfWrapClienti
xmlns="http://schemas.datacontract.org/2004/07/aaa"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<WrapClienti>
<CODRETE>111</CODRETE>
<CODICE>111</CODICE>
<NOME>aaa</NOME>
<INDIRIZZO>aaa</INDIRIZZO>
<CITTA>aaa</CITTA>
<CAP>aaa</CAP>
<PROV>aa</PROV>
<CODICEFISCALE>111</CODICEFISCALE>
<PIVA>2236401111236</PIVA>
<EMAIL/>
<ESPOSIZ_CONTABILE>111</ESPOSIZ_CONTABILE>
<STATO>FALSE</STATO>
</WrapClienti>
</ArrayOfWrapClienti>
<RETISTA>1111</RETISTA>
<HASHEDSTRING>oklkokokokok</HASHEDSTRING>
</XMLRequest>
</SetClientiXML>
我也创建了这个类:
[DataContract]
public class XMLRequest
{
[DataMember]
public List<WrapClienti> XML;
[DataMember]
public string RETISTA;
[DataMember]
public string HASHEDSTRING;
public XMLRequest() { }
public XMLRequest(List<WrapClienti> x, string r, string h)
{
this.HASHEDSTRING = h;
this.XML = x;
this.RETISTA = r;
}
}
,现在的portotype是:
public GenericResponse SetClientiXML(XMLRequest xr)
答案 0 :(得分:0)
这有用吗?
string input =
"<ArrayOfWrapClienti xmlns=\"http://schemas.datacontract.org/2004/07/MultipayOnline\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<WrapClienti>" +
"<CODRETE>0018</CODRETE>" +
"<CODICE>20685</CODICE>" +
"<NOME>A.T.E.R. Azienda Territoriale</NOME>" +
"<INDIRIZZO>PIAZZA POZZA</INDIRIZZO>" +
"<CITTA>Verona</CITTA>" +
"<CAP>37123</CAP>" +
"<PROV>VR</PROV>" +
"<CODICEFISCALE>00223640236</CODICEFISCALE>" +
"<PIVA>223640236</PIVA>" +
"<EMAIL/>" +
"<ESPOSIZ_CONTABILE>937,02</ESPOSIZ_CONTABILE>" +
"<STATO>FALSE</STATO>" +
"</WrapClienti>" +
"</ArrayOfWrapClienti>";
input = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + input;
答案 1 :(得分:-1)
以下是序列化和反序列化xml的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleApplication2
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
SetClientiXML client = new SetClientiXML()
{
xmlRequest = new XMLRequest()
{
arrayOfWrapClienti = new ArrayOfWrapClienti()
{
wrapClient = new List<WrapClient>() {
new WrapClient {
codrete = "0018",
codice = "20685",
nome = "A.T.E.R. Azienda Territoriale",
indirizzo = "PIAZZA POZZA",
citta = "Verona",
cap = "37123",
prov = "VR",
codiceFiscale = "00223640236",
piva = "223640236",
esposizContabile = "937,02",
stato = false
}
}
}
},
retista = "3303903",
hashedString = "oklkokokokok"
};
XmlSerializer serializer = new XmlSerializer(typeof(SetClientiXML));
StreamWriter writer = new StreamWriter(FILENAME);
serializer.Serialize(writer, client);
writer.Flush();
writer.Close();
writer.Dispose();
XmlSerializer xs = new XmlSerializer(typeof(SetClientiXML));
XmlTextReader reader = new XmlTextReader(FILENAME);
SetClientiXML newClient = (SetClientiXML)xs.Deserialize(reader);
}
}
[XmlRoot("SetClientiXML")]
public class SetClientiXML
{
[XmlElement("XMLRequest")]
public XMLRequest xmlRequest { get; set; }
[XmlElement("RETISTA")]
public string retista { get; set; }
[XmlElement("HASHEDSTRING")]
public string hashedString { get; set; }
}
[XmlRoot("XMLRequest")]
public class XMLRequest
{
[XmlElement("ArrayOfWrapClienti")]
public ArrayOfWrapClienti arrayOfWrapClienti { get; set; }
}
[XmlRoot("ArrayOfWrapClienti")]
public class ArrayOfWrapClienti
{
[XmlElement("WrapClient")]
public List<WrapClient> wrapClient { get; set; }
}
[XmlRoot("WrapClient")]
public class WrapClient
{
[XmlElement("CODRETE")]
public string codrete { get; set; }
[XmlElement("CODICE")]
public string codice { get; set; }
[XmlElement("NOME")]
public string nome { get; set; }
[XmlElement("INDIRIZZO")]
public string indirizzo { get; set; }
[XmlElement("CITTA")]
public string citta { get; set; }
[XmlElement("CAP")]
public string cap { get; set; }
[XmlElement("PROV")]
public string prov { get; set; }
[XmlElement("CODICEFISCALE")]
public string codiceFiscale { get; set; }
[XmlElement("PIVA")]
public string piva { get; set; }
[XmlElement("EMAIL")]
public string email { get; set; }
[XmlElement("ESPOSIZ_CONTABILE")]
public string esposizContabile { get; set; }
[XmlElement("STATO")]
public Boolean stato { get; set; }
}
}