问题描述
使用此服务,我想使用senchatouch2中的POST方法将数组值存储到数据库中..服务写入(WCF)
Using this service i want to store array value into database using POST method in senchatouch2..Service is written in (WCF)
服务声明:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/Check1")]
int Psngr(string[] FirstName);
服务定义:
public static int Psngr(string[] FirstName)
{
List<Psgr> psgr = new List<Psgr>();
var getVal = from s in FirstName select s;
int count = getVal.Count();
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["db"].ToString());
con.Open();
using (var cmd = new SqlCommand("SP_InsertCheck1", con))
{
int result;
cmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < count; i++)
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@FirstName", FirstName[i]);
using (var Da = new SqlDataAdapter(cmd))
using (var Ds = new DataSet())
{
Da.Fill(Ds);
result = Convert.ToInt16(Ds.Tables[0].Rows[0]["Result"].ToString());
}
}
return 1;
}
}
我通过ajax请求访问了此服务,如下所示:
I accesssed this service through my ajax request as follows:
Ext.Ajax.request({
url:'http://ws.easy4booking.com/E4b.svc/Check1',
method:'POST',
disableCaching: false,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
params: {
FirstName:fname_toString, //FirstName:["Sam","Paul"],
},
success:function(response) {
console.log(response);
}
});
当我访问上述服务lik时,出现以下错误
When I accessed this service lik mentioned above i got following error
请求错误:
在System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(消息,Object []参数)在System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(消息消息,Object []参数)位于System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(消息,Object []参数)位于System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(消息,Object []参数)位于System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)位于System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean)上的System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)isOperationContextSet)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters) atSystem.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) atSystem.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) atSystem.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) atSystem.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) atSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(BooleanisOperationContextSet)
推荐答案
当v使用POST方法在SenchaTouch2中传递参数时,请在Ajax Request之类的 jsonData 中使用
When v use POST method to pass parameters in SenchaTouch2 use jsonData in Ajax Request like,
这篇关于使用senchatouch2中的POST方法将数组作为参数发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!