当我使用URItemplate修改web服务方法的传入消息时,出现以下异常,URItemplate不是空的。
System.IndexAutoFrangeException异常:索引超出数组的界限。在System.ServiceModel.Dispatcher系统服务模型乌里坦普尔先生ateDispatchFormatter.DeserializeRequest请求(消息,对象[]参数)位于System.ServiceModel.Dispatcher系统服务模型显示atchOperationRuntime.DeserializeInputs(MessageRpc&rpc)位于System.ServiceModel.Dispatcher系统服务模型显示atchOperationRuntime.InvokeBigin(消息RPC&rpc)在System.ServiceModel.Dispatcher系统服务模型.免疫tableDispatchRuntime.ProcessMessage5表(MessageRpc&rpc)位于System.ServiceModel.Dispatcher系统服务模型.免疫tableDispatchRuntime.ProcessMessage31(MessageRpc&rpc)位于System.ServiceModel.Dispatcher系统服务模型.MessageRpc.进程(布尔等操作上下文集)
所以它适用于
[WebInvoke(Method = "POST", UriTemplate = "/")]
[WebInvoke(Method = "PUT", UriTemplate = "/")]
但不是
[WebInvoke(Method = "PUT", UriTemplate = "/id")]
[WebInvoke(Method = "POST", UriTemplate = "/id ")]
下面是我如何修改消息的
public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
{
//get the request as xml
string xml = request.ToString();
if (!string.IsNullOrWhiteSpace(xml))
{
//create a new xml document
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XElement xmlElement = XElement.Load(new XmlNodeReader(doc));
XDocument sortedXml = new XDocument();
XElement root = new XElement(xmlElement.Name);
sortedXml.Add(root);
Sort2(xmlElement, root);
request = Message.CreateMessage(request.Version, null, new SimpleMessageBody(sortedXml.ToString()));
}
return null;
}
public class SimpleMessageBody : BodyWriter
{
string xmlContent;
public SimpleMessageBody(string content)
: base(true)
{
this.xmlContent = content;
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
{
using (StringReader stringReader = new StringReader(xmlContent))
{
using (XmlReader xmlReader = XmlTextReader.Create(stringReader))
{
writer.WriteNode(xmlReader, true);
}
}
}
}
“可以将消息用作参数
只有当它是
“手术”
那我有什么选择。。