Web Service method name is not valid error using HTTP GET
I just learned something new about using HTTP GET to access .NET web services. HTTP GET returns a "Web Service method name is not valid." error if you pass arguments by reference.
Why use HTTP GET? Calling Web Services via HTTP GET can be useful for stress testing with Microsoft ACT. The systems engineers can record a simple script calling multiple web services with different arguments in no time. It is possible to use HTTP POST in Microsoft ACT but it requires some coding skills.
I wanted to call this test method:
[WebMethod]
public int HelloWorld(string sayThis, ref string XmlOut)
But I ran into several issues. The first problem is well documented; you have to enable the HttpGet protocol to call .NET WebServices with GET requests, otherwise you get this error:
[InvalidOperationException]: Request format is unrecognized.
at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig)
at System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The problem went away after I added the following to my Web.Config:
<system.web>
...
<webServices>
<protocols>
<add name="HttpPost" />
</protocols>
</webServices>
</system.web>
The GET request worked but still I got this error:
System.InvalidOperationException: HelloWorld Web Service method name is not valid.
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
After modifying the test method a few times I found the problem; arguments by reference is not supporte when using HTTP GET. Why? I don't know. I can understand that complex arguments like objects are not supported but I cannot see why ref arguments are broken since the return value is passed in the output XML.
I worked around the problem by implementing a full Web Service client using HTTP POST.
No comments:
Post a Comment