I've been fighting a WebService for the past few days. I wrote a simple service, and managed to get it running locally. I tried to get it to work on the test server, but only got a response: "Internal Service Error". In researching that message, I read that web services cannot be used in DNN, and I needed to use IWebCF. After a fruitless day working on that, I was doing more googling about "Internal Service Error". I finally came across a message that solved my problem with the initial service. I did not need IWebCF at all.
There are lots of questions posted about calling a web service from jQuery, as well as the error message. Not many answers, though. In case it will help
someone in the future, here is my solution:
I added a new DotnetNuke Dynamic Module item in DesktopModules. I removed the Edit_ and View_ files and created my own SayHello.ascx.
<%@ Control Language="C#" Inherits="MWIWeb.Modules.SayHello.SayHello" CodeFile="SayHello.ascx.cs" AutoEventWireup="true" %>
<script language="javascript" type="text/javascript">
$(document).delegate('.SayHello', 'click', function (e) {
e.preventDefault();
$.ajax(
{
type: "POST",
url: "MyService.asmx/HelloWorld",
data: "",
dataType: "html",
success: function (msg) {
msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
errorThrown);
}
});
});
</script>
<asp:Button ID="cmdSayHello" Text="Say Hello" runat="server" class="SayHello" />
***********************************************************************************************************
In the DNN root folder, I added a WebService item call MyService.
public class MyService : System.Web.Services.WebService {
public MyService () {
}
[WebMethod]
public string HelloWorld() {
HttpContext.Current.Response.Write("Hello World");
}
}
***********************************************************************************************************
To make it work on our test server, I added this text to the web.config before the </system.web>:
<webServices>
<protocols>
<add name="HttpSoap, HttpPost, Documentation, HttpPostLocalhost" />
</protocols>
</webServices>
Finally, go into Host | Extensions and create a new Custom Module from Sayhello.ascx.
(I didn't really use "MyService" and "SayHello". I changed the names to protect the innocent.)
Cheers!
Dan
On a clear disk, you can seek forever.