[英]Loosing xml content when POST to wcf REST
am loosing xml content when calling wcf service via post. 通过post调用wcf服务时丢失xml内容。 I see only "<" to wcf method.
我只看到“ <”到wcf方法。 Am passing xml content like this: samplesample.
正在传递xml内容,例如:samplesample。
Client: 客户:
jQuery.support.cors = true;
$.ajax({
type: 'POST',
url: 'http://localhost:48677/MYSVC.svc/ParseXML/<?xml version=1.0 encoding=UTF-8?><node>sample</node><node1>sample</node1>',
cache: false,
contentType: 'text/xml;charset=UTF-8',
dataType: 'json',
processData: true,
success: function (msg) {
},
error: function (err) {
}
});
Service Interface: 服务接口:
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "ParseXML/{xmlContent}")]
Stream ParseXML(string xmlContent);
Also incorporated wrapper as per: http://vivekcek.wordpress.com/2012/06/14/wcf-rest-service-accepting-raw-xml-webcontenttypemapper/ 还根据以下内容合并了包装器: http : //vivekcek.wordpress.com/2012/06/14/wcf-rest-service-accepting-raw-xml-webcontenttypemapper/
If I pass non-xml string, my service get called but proper xml content it is not. 如果我传递非xml字符串,则会调用我的服务,但不会调用正确的xml内容。
Also included following line in both service & asp.net web.config: 在service和asp.net web.config中还包括以下行:
<httpRuntime requestValidationMode="2.0" maxUrlLength="4096" requestPathInvalidCharacters="" useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000" targetFramework="4.5"/>
I also tried with this: requestPathInvalidCharacters="<,>,*,%,:,\\,?" 我也尝试过这样做:requestPathInvalidCharacters =“ <,>,*,%,:,\\ ,?” but didn't help
但没有帮助
Please guide me how to pass proper xml content to wcf! 请指导我如何将适当的xml内容传递给wcf!
Updated: 更新:
WHile calling service from httpwebresponse, am getting below error: 从httpwebresponse调用服务时,出现以下错误:
The server encountered an error processing the request.
服务器在处理请求时遇到错误。 The exception message is 'Incoming message for operation 'ParseXML' (contract 'IXmlParseService' with namespace ' http://tempuri.org/ ') contains an unrecognized http body format value 'Xml'.
异常消息是“操作'ParseXML'的传入消息(合同'IXmlParseService',名称空间为' http://tempuri.org/ ')包含无法识别的http正文格式值'Xml'。 The expected body format value is 'Raw'.
预期的正文格式值为“ Raw”。 This can be because a WebContentTypeMapper has not been configured on the binding.
这可能是因为尚未在绑定上配置WebContentTypeMapper。 See the documentation of WebContentTypeMapper for more details.'.
有关更多详细信息,请参见WebContentTypeMapper的文档。 See server logs for more details.
有关更多详细信息,请参见服务器日志。 The exception stack trace is:
异常堆栈跟踪为:
at System.ServiceModel.Dispatcher.HttpStreamFormatter.GetStreamFromMessage(Message message, Boolean isRequest) at System.ServiceModel.Dispatcher.HttpStreamFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(Messa
在System.ServiceModel.Dispatcher.HttpStreamFormatter.GetStreamFromMessage(消息消息,布尔值isRequest)在System.ServiceModel.Dispatcher.HttpStreamFormatter.DeserializeRequest(消息消息,Object []参数)在System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(消息消息, System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(消息,Object []参数)位于System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&rpc)位于System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&Discatcher .ImmutableDispatchRuntime.ProcessMessage31(Messa geRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&rpc) System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)上的Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&rpc)
Your xml is not being properly encoded for url use. 您的xml未被正确编码以供url使用。 You can use encodeURIComponent() to encode the content.
您可以使用encodeURIComponent()对内容进行编码。
var payload=encodeURIComponent('<?xml version=1.0 encoding=UTF-8?><node>sample</node><node1>sample</node1>');
$.ajax({
type: 'POST',
url: 'http://localhost:48677/MYSVC.svc/ParseXML/'+payload,
data:{'xmlContent':payload},
cache: false,
contentType: 'text/xml;charset=UTF-8',
dataType: 'json',
processData: true,
success: function (msg) {
},
error: function (err) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.