Reputation: 888
I have created asmx service, how do I invoke it via "URL"?
Here is my code:
[WebMethod]
public string start(string id, string name)
{
string newname = name;
return newname;
}
Here is my current URL:
url = "http://localhost:XXXXX/WebService.asmx/start?id=" +id+ "&name="+name;
Here is my "Web.config":
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5">
</compilation>
<httpRuntime maxRequestLength="1000000"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Upvotes: 2
Views: 3527
Reputation: 1915
You can decorate your method to allow HTTP GET requests
[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public string start(string id, string name)
{
string newname = name;
return newname;
}
and do the following in web.config file
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
</protocols>
Setting the UseHttpGet property to true might pose a security risk for your application if you are working with sensitive data or transactions. In GET requests, the message is encoded by the browser into the URL and is therefore an easier target for tampering.
Note that this method of performing GET requests does come with some security risks. According to the MSDN documentation for UseHttpGet:
Hope this helps
Upvotes: 3