Click here to Skip to main content
15,885,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello my wcf code is below:

Interface:
C#
[OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped,
         UriTemplate = "/SaveURLTable")]
        Int64 SaveURLTable(string URL, string UniqueID);


Method:

C#
public Int64 SaveURLTable(String URL, String UniqueID)
{
    // my code here with return value
}


now i m able to call this by making httprequest call from IE10, FF, Chrome like modern web browser but when i call this from IE8 then its giving me following error:

XML
<p>The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details. The exception stack trace is: </p>
      <p>   at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</p>



Found in fiddler.

my json code for modern browser is below:

$.ajax({
                type: "POST",
                crossDomain: true,
                url: query,
                data: '{"URL": "' + dbString + '","UniqueID": ""}',
                contentType: "application/json; charset=utf-8",
                dataType: "XML",
                processdata: true,
                success: function (data1) {
                    if (data1 != null) {
                        var data = data1;
			alert(data);
                    }
                },
                error: function (response, textStatus, errorThrown) {
                    alert(response.responseText);
                }
            });



and my IE8 XDR code is below:

C#
var postdata = '{"URL": "' + dbString + '","UniqueID": ""}';
        if (window.XDomainRequest) {
            var xdr = new XDomainRequest();
            if (xdr) {
                xdr.onload = function () {
                    data = xdr.responseText;
                    alert(data);

                }
                xdr.onerror = function () { /* error handling here */ }
                xdr.open('POST', query);
                xdr.send(JSON.stringify(postdata));
            }
        }



My httprequest code is working correct but XDR code is not working and giving me above error. please help me to solve this guys...

I want to make post request with data from IE8, please help me.
Posted
Comments
Faisalabadians 24-Feb-14 5:39am    
JSON.stringify(postdata);

when you are already making JSON by your self then y used JSON.stringify()? do you know what does this function do? if you make and object rather then JSON like below, then you should use JSON.stringify(postdata);

var postdate = {
URL: dbString,
UniqueID:""
}
Member 10359492 24-Feb-14 23:40pm    
I also use postdata directly without JSON.stringify(postdata) then also it gives me the same error. I googled and found like this but still i fail, that's why put this question here so someone suggest me the perfect understanding and solve my problem.
Faisalabadians 25-Feb-14 2:10am    
did you try to make call by using FIDDLER? run your service and put break point on your method and use FIDDLER to make call. let me know if this call hits break point.

1 solution

Your OperationContract is not valid. Try changing it and re run.

C#
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormate.Json,
UriTemplate = "/SaveURLTable")]
Int64 SaveURLTable(string URL, string UniqueID);


Moreover! If you are sending data in JSON format, then only specify your custom object in parameter.

EDIT: Change your UriTemplate like this:

C#
/SaveURLTable?URL={URL}&UniqueID={UniqueID}


You have set
JavaScript
contentType: "application/json; charset=utf-8"
but again, you are not sending any JSON. Remove this Content-Type and then try again.
 
Share this answer
 
v2
Comments
Member 10359492 13-Mar-14 0:40am    
Thanx for the reply but i dont want the method that accepts only Json or XML as request format, i made a restful service where method works as per the request coming from client. If dataType: "XML" then response will be in XML and if dataType: "JSON" then response will be in JSON. All my get method is working correctly but this post method is not working plz help me.
Faizan Mubashar 13-Mar-14 1:22am    
Whats the Error Message?
Member 10359492 13-Mar-14 2:50am    
The server encountered an error processing the request. The exception message is 'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details. The exception stack trace is:

at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.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.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)


According to the error msg you were true but i dont want to so like that as i said in my previous comment.
Faizan Mubashar 13-Mar-14 4:57am    
Then make it Get method instead of POST.
Member 10359492 13-Mar-14 8:46am    
No dear, i cant make it GET instead of POST. Because its working fine in httprequest and online now but not working with XDR and for that i can't change the work that is already done. If you have any other suggestion then plz tell me... thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900