Joh*_*ams 2 c# wcf constructor asmx
我小心翼翼地进入 WCF,试图按照教程将我的 ASMX 项目转换为一个新的 WCF 项目,我偶然发现了一个关于在 WCF 中编写构造函数的谜团。
我的 ASMX 网络服务允许我有一个构造函数(参见:同名,无返回值):
namespace sdkTrimFileServiceASMX
{
public class FileService : System.Web.Services.WebService
{
Database db;
string g_EventSource = "CBMI-TrimBroker";
string g_EventLog = "Application";
public FileService()
{
try
{
if (!EventLog.SourceExists(g_EventSource))
EventLog.CreateEventSource(g_EventSource, g_EventLog);
}
catch (InvalidOperationException e)
{
e.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
我将其转换为 WCF 服务应用程序的尝试给出了以下编译器投诉:
The namespace 'sdkTRIMFileServiceWCF' already contains a definition for 'FileService'
Run Code Online (Sandbox Code Playgroud)
这是 WCF 代码(开始片段):
namespace sdkTRIMFileServiceWCF
{
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class FileService : IFileService // err msg points to this line
{
Database db;
string g_EventSource = "CBMI-TrimBroker";
string g_EventLog = "Application";
public FileService()
{
try
{
if (!EventLog.SourceExists(g_EventSource))
EventLog.CreateEventSource(g_EventSource, g_EventLog);
}
catch (InvalidOperationException e)
{
e.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
这与构造函数的存在无关。我相当确定这是一个复制/粘贴错误 - 在您的应用程序的任何文件中搜索“FileService”一词,您将找到具有该名称的另一个类或命名空间声明(在同一命名空间中)。
| 归档时间: |
|
| 查看次数: |
3180 次 |
| 最近记录: |