Showing posts with label web services. Show all posts
Showing posts with label web services. Show all posts

Request format is unrecognized for URL unexpectedly ending in methodname

This is the exception I am getting when I try to access web services from my web site. I just created a web service and tried to access the service from the browser using the get request. But I got the invalid operation exception. See complete exception details below:

System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/MethodName'

So, Before we will go to know the solution for it, I want to explain the reason behind this.

A .NET web service supports three protocols named HTTPGET, HTTPPOST and SOAP. When .NET released I mean, ASP.NET v1.0 all these three protocols enabled by default. So, any requests which made from the browser which belongs to a web service will be responded without any issues. But when come to ASP.NET 1.1 version the protocols HTTPGET and HTTPPOST are disabled by default. The only reason is SECURITY issue. So until you explicitly enable them no web service request will be processed if you call them in the format domain/webservice.asmx/methodname [Get/Post].

But, where as if you call direct web service from browser using SOAP request that will work and will give result what you need. But, if you make any GET or POST request then only the problem will come. 

RESOLUTION:

To enable these protocols in the application level simply we need to change the application config file. Web.config. Add below lines to the web.config to enable these protocols.











So, this webservices tag will go inside the <system.web> namespace. With the above lines, the protocols enabled and they listen the request and respond accordingly for that application. Sometimes you may need to enable these protocols in system level. I mean to all applications in the server should have these protocols enabled. Then below is the solution for it.

Find machine.config file and open it in nice editor like visual studio. Before do any changes please take a backup of the file. Now find the protocols section and add the below lines if they are not already there.






Hope, you understood it well and you are now knew the reason behind of the above exception message. Please know me the feedback.

Read More...

Steps to add a Web service 2.0 in SharePoint 2007

Today at my work, I need to implement JQuery in SharePoint on a module. I need to make AJAX calls to get the data from the database depending on the value in a text box. So, I choose JQuery, because I know it well and it will take very less time to implement. But for JQuery I need to create page web methods. But SharePoint doesn’t support Page web methods because SharePoint is completely built upon ASP.NET 2.0.

So, what is the solution, how can I make a call to the server and get the data from DB? After thought some time about it, finally I got a brilliant and better idea of using web services. Please follow the steps below to implement Web services in SharePoint.

  • We are using client side technologies like JQuery etc to call Web service to get the data from server. By default, it is not supported. For that, we need the supporting DLL's[System.Web.Script.Services] for the Web service script on the SharePoint server. These DLL's are needed to process the web service request and send the response[JSON]. For those DLL, you need to install the Ajax extensions 1.0.
  • Create a web service using Visual studio. It will generate two files webservice.asmx and webservice.cs. Write all the web methods required inside the webservice.cs file. I will explain you with an example more detail later in this post.
  • Now, we need a location to keep our *.cs [webservice.cs] file. So, for that, create App_Code folder in the SharePoint site file system virtual directory root [c:\inetpub\…\wss\virtualdirectories\portnumber]. You can find the advantages of using App_code folder, in SharePoint web application in this post.
  • By default SharePoint won't allow the script handlers and http modules. For this reasons, we need to make the web.config changes as explained in this post.
  • Change the settings in central admin to remove asmx extension from blocked file types. See it here.

After you are ready with all the above steps, then please follow the steps below.

  • Check the related dll’s are added in the system, after installed Ajax extensions. Below are the namespaces you required in the webservice.cs file.
  • using System.Web.Services;
    using System.Web.Script.Services;

  • Copy the webservice.asmx file to the SharePoint website virtual directory file system path [c:\inetpub\…\wss\virtualdirectories\portnumber\].
  • Copy the file webservice.cs file, and paste it in the app_code folder of the SharePoint web site.
  • Please follow the post web.config changes as explained.
  • Central administration changes as explained above.

There we are done with the process. This is really working great and we can solve really very difficult problems like all scenarios where we need to communicate with DB without doing post back etc. This is very smooth and fast way of retrieving results. I like to hear feedback. This is the one of the best solutions I found. Please post any problems if you face while implementing this process.

Isn't this a valuable find?

Read More...
Related Posts with Thumbnails
GiF Pictures, Images and Photos