0

I am using AngularJS and WCF Services. My problem is related to post method and the response I am getting back from the WCF Service.

The declaration of the method in Interface in WCF Servvice looks like this:

[OperationContract]
[WebInvoke(
    Method = "POST",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "UpdateBusiness")]
void UpdateBusiness(Business business);

The Method looks like this:

public void UpdateBusiness(Business business)
{
    BusinessManager manager = new BusinessManager();
    manager.UpdateBusiness(business);
}

The call from AngularJS looks like this:

$http({
    url: app.service + '/UpdateBusiness',
    method: "POST",
    headers: {
        'Content-Type': 'application/json; charset=utf-8'
    },
    data: $scope.business
})
.success(function (data, status, headers, config) {
    console.log("Done status: " + status);
    console.log("Done status: " + data);
})
.error(function (data, status, headers, config) {
    console.log("Error status: " + status);
    console.log("Error status: " + data);
});

Now the problems is: When I post data to WCF Service, it actually receives the data correctly, further down, it updates correct records in the DB. Now, in the browser, after backend process is completed and the response is returned from the server I get this error in the console:

no element found
"Done status: 200"
"Done status: "

So basically, at first look it looks like that there is no error returned from the server, but when I check the details I see this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Service</title>
    <style>
        //I have removed the styling code to keep the post short
    </style>
  </head>
  <body>
    <div id="content">
      <p class="heading1">Service</p>
      <p xmlns="">Method not allowed. Please see the <a rel="help-page" href="http://localhost/Server/Production.svc/help">service help page</a> for constructing valid requests to the service.</p>
    </div>
  </body>
</html>

What should I do to remove these errors. Thanks

EDIT: The headers and response look like this:

Request URL:    http://localhost/Service/Production.svc/UpdateBusiness
Request Method:     POST
Status Code:    HTTP/1.1 200 OK

Request Headers 09:23:21.000:

User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0
Referer:    http://localhost/AdminPanel/
Pragma: no-cache
Host:   localhost
Content-Type:   application/json; charset=utf-8
Content-Length: 379
Connection: keep-alive
Cache-Control:  no-cache
Accept-Language:    en-US,en;q=0.5
Accept-Encoding:    gzip, deflate
Accept: application/json, text/plain, */*

Request Body:

{"BusinessID":3,"BusinessName":"My Business ","BusinessTags":{"ErrorCode":0,"ErrorDetail":"","ErrorMessage":"","BusinessTags":[]},"BusinessTagsText":"","CategoryID":9,"Email":"[email protected]","Embed":true,"Enabled":false,"Facebook":"www.facebook.com/mybusiness","Phone":"111 622 422","PhoneType":"Delivery","Twitter":"www.twitter.com/mybusiness","URL":"www.mybusiness.com"}

Response Headers Δ67ms:

X-Powered-By:   ASP.NET
X-AspNet-Version:   4.0.30319
Server: Microsoft-IIS/8.5
Date:   Mon, 16 Jun 2014 04:23:21 GMT
Content-Length: 0
Cache-Control:  private
No Response Body 

EDIT 2: Fiddler response: I have change the return type to String to see if something is returned as well and here is the raw view:

HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 16 Jun 2014 04:39:38 GMT

f
"Done is done."
0
4
  • what does HTTP request look like? Do you reproduce this response if you post using curl or a similar tool? Commented Jun 16, 2014 at 4:13
  • I have edited my post. It contains response and headers now. I don't have curl at the moment. However, I don't see any error in Fiddler. Commented Jun 16, 2014 at 4:40
  • this last response is far from json : ) Commented Jun 16, 2014 at 4:43
  • I know its not json, it just to debug. So by adding a return type of type string (before it was void) fixed no element found error. I am not sure if that is correct solution or not. Commented Jun 16, 2014 at 4:54

1 Answer 1

1

Change return type from void to String or something valid.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.