I have a Restful WCF service sitting on another server configured with the WebGet attribute to respond to the HTTP Get method. I know that the service works correctly, because I can call the service directly through the browser and manually do Get with Fiddler and get the correct answer.
I have an Asp.NET project on my local machine that calls this service with the following code:
Proxy interface "IProductService":
using System.ServiceModel; using System.ServiceModel.Web; namespace Hugo.Infrastructure.Services.Products { [ServiceContract] [XmlSerializerFormat] public interface IProductService { [OperationContract(Name = "GetProductById")] [WebGet(UriTemplate = "Products/Titles/{id}", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)] TitleDto GetTitleById(string id); } }
Implementation of "ProductService":
using System.ServiceModel; namespace Hugo.Infrastructure.Services.Products { public class ProductService : ClientBase<IProductService>, IProductService { public TitleDto GetTitleById(string id) { return Channel.GetTitleById(id); } } }
Associated Web.config section:
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"> <baseAddressPrefixFilters> </baseAddressPrefixFilters> </serviceHostingEnvironment> ... <client> <endpoint address="http://server/directory/product.svc" bindingConfiguration="ProductServiceBinding" binding="webHttpBinding" behaviorConfiguration="productService" contract="Project.Infrastructure.Services.Products.IProductService" name="ProductServiceRest" /> </client> <behaviors> ... <endpointBehaviors> <behavior name="productService"> <webHttp /> </behavior> ... </endpointBehaviors> </behaviors> </system.serviceModel>
This works fine when we call a method from a page in a project, however it is mistaken in this line return Channel.GetTitleById(id); when we call it from the WCF service from the same project. The error we get is the HTTP 405 error 'Method not allowed'. When we look at the IIS logs on the remote server, we see that the ProductService proxy makes an HTTP GET request when the method invokes from the page, but it makes an HTTP POST request when the method is called from the WCF service. The POST method is not configured for the service, so error 405.
Even when the page and the service are in the same folder and namespace, we still get the same error from the service. If we use the classic asmx soap service, a GET call is made instead, and the service makes and answers correctly. If we manually get from the WCF service using the System.Net.WebRequest object, the service is successfully called.
Bottom line, the WCF proxy client tries to make a POST instead of GET when using from another WCF Rest service, but it works correctly when used from a page or to a large extent elsewhere.
Help me please!