我的 WCF Web 服务 PROGRAM.CS 有这个控制台主机
class Program
{
static void Main(string[] args)
{
WebServiceHost Host = new WebServiceHost(typeof(Service1));
try
{
Host.Open();
Console.ReadLine();
Host.Close();
}
catch (Exception e)
{
Console.WriteLine(e);
Host.Abort();
}
}
这是我的主机 app.config
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="Csvpost.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
这是服务的 Service1 类
public class Service1 : IService1
{
public Stream HandleMessage(Stream request)
{
StreamReader reader = new StreamReader(request);
string text = reader.ReadToEnd();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
MemoryStream ms = new MemoryStream(encoding.GetBytes(text));
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
string[] sites = text.Split('\n');
int y = sites.Length;
int i;
for (i = 0; i < y; i++)
{
/logic/
System.Data.SqlClient.SqlConnection con;
System.Data.SqlClient.SqlCommand cmd;
con = new System.Data.SqlClient.SqlConnection(connection);
cmd = new System.Data.SqlClient.SqlCommand(query, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
return ms;
}
}
我的主机一开始运行就会关闭。我犯了什么错误?提前致谢。