最初の 2 つの関数はうまく機能しますが、3 番目の関数はエラーが不明です。ここにすべてのコードがあります。最後の機能を完了する方法を教えてください。
WebService1.asmx のコード
using System.ComponentModel;
using System.Web.Services;
using System.Text;
using System.IO;
namespace WebApplication1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorldFun1()
{
return "Hello World";
}
[WebMethod]
public string HelloWorldFun2(string str)
{
return "Hello World,"+str;
}
[WebMethod]
public string Write_to_File(string str)
{
StreamWriter _testData = new StreamWriter(Server.MapPath("~/output.txt"), true);
_testData.WriteLine(str); // Write the file.
_testData.Flush();
_testData.Close(); // Close the instance of StreamWriter.
_testData.Dispose(); // Dispose from memory.
return str;
}
}
}
Default.aspx のコード
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>WebService</title>
<script type="text/javascript" language="javascript">
function func1()
{
WebApplication1.WebService1.HelloWorldFun1(onSuccess,onFail,'Span1');
}
function func2()
{
var txt=document.getElementById('Text1').value;
WebApplication1.WebService1.HelloWorldFun2(txt,onSuccess,onFail,'Span2');
}
function write()
{
var txt = document.getElementById("Span1").innerHTML;
WebApplication1.WebService1.Write_to_File("kkkkkkkkkk",onSuccess,onFail,'Span3');
}
function onSuccess(value,context)
{
document.getElementById(context).innerHTML=value;
}
function onFail(value)
{
alert(value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
<Services>
<asp:ServiceReference Path="~/WebService1.asmx" />
</Services>
</asp:ScriptManager>
<input id="Button1" type="button" value="button" onclick="func1()" /> <span id="Span1"></span>
<hr />
<input id="Text1" type="text" /><input id="Button2" type="button" value="button" onclick="func2()" /><span id="Span2"></span>
</form>
<input id = "WTF" type = "button" value = "write" onclick ="write()"/><span id="Span3"></span>
</body>
</html>