0
votes

Using this service i want to store array value into database using POST method in senchatouch2..Service is written in (WCF)

Service declaration :

[OperationContract]
[WebInvoke(Method = "POST", 
           ResponseFormat = WebMessageFormat.Json,
           RequestFormat = WebMessageFormat.Json,
           BodyStyle = WebMessageBodyStyle.Wrapped,
           UriTemplate = "/Check1")]
int Psngr(string[] FirstName);

Service definition :

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;
    }
}

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);
    }
});

When I accessed this service lik mentioned above i got following error

Request Error:

The server encountered an error processing the request. The exception message is 'The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'Psngr'. Encountered unexpected character 'F'.'. See server logs for more details. The exception stack trace is:

at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.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(MessageRpc& 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)

2
I would say that you monitor on how the Raw request looks like. Use tools like Fiddler or WireShark to see the raw request. Also you can enable tracing on the WCF service and see what is causing the issue.Rajesh
I dont understand where s d exact problem..Problem s in sencha code or service? kindly reply meAnnie
Enable wcf trace, use svcTraceViewer.exe to view them IMO - this will help to find WHERE the error comes from.evgenyl
Also, Are you sure you sending array and not string?evgenyl
Yes m sure m sending ARRAY oly ..my array pass lik FirstName:["Annie","Dev","Anish","Angel"]Annie

2 Answers

1
votes

When v use POST method to pass parameters in SenchaTouch2 use jsonData in Ajax Request like,

Ext.Ajax.request({ url:'', method:'POST', disableCaching:false, headers: { 'Accept':'application/json', 'Content-Type':'application/json' }, jsonData: { FirstName:fname //{"FirstName":["Sam","paul"]} }, success: function(response) { console.log(response.responseText); }, failure: function(response) { console.log(response.responseText); }, });

0
votes

When your client does a request to the WCF Rest service the raw request should look something like below:

POST http://localhost/SampleService/RestService/Check1 HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: localhost
Content-Length: 33

{"FirstName":["Sam","paul"]}

Seems like your sencha code is passing the string[] which WCF is not able to deserialize. You might consider to pass it as jsonData rather than param.

Also look at this link which might help.(The service they are trying to consume is in Spring MVC but i guess it should be the same for WCF service as well)