C# 在C中运行ServiceHost(WCF)的Open函数时System.Xml.XmlException#
当我将代码从一台计算机(a)移到另一台计算机(B)时,我遇到了一个问题。问题是,当代码运行以打开ServiceHost的函数时,我遇到了以下异常,尽管服务仍然可以打开。换句话说,此异常不影响服务。这个问题不会发生在计算机A中C# 在C中运行ServiceHost(WCF)的Open函数时System.Xml.XmlException#,c#,wcf,C#,Wcf,当我将代码从一台计算机(a)移到另一台计算机(B)时,我遇到了一个问题。问题是,当代码运行以打开ServiceHost的函数时,我遇到了以下异常,尽管服务仍然可以打开。换句话说,此异常不影响服务。这个问题不会发生在计算机A中 Exception thrown: 'System.Xml.XmlException' in System.Xml.dll Exception thrown: 'System.Xml.XmlException' in System.Xml.dll Exception thr
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
Exception thrown: 'System.Xml.XmlException' in System.Xml.dll
我创建了我自己的TRFServiceHost,它从ServiceHost继承如下
public class TRFServiceHost : ServiceHost
{
private string _configureFilePath;
public TRFServiceHost(Type serviceType, params Uri[] baseAddresses) : base(serviceType, baseAddresses)
{
}
protected override void ApplyConfiguration()
{
this._configureFilePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
"TRFServerModule.config";
if (!File.Exists(this._configureFilePath))
{
base.ApplyConfiguration();
return;
}
var configFileMap = new ExeConfigurationFileMap { ExeConfigFilename = this._configureFilePath };
var config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap,
ConfigurationUserLevel.None);
var serviceModel = ServiceModelSectionGroup.GetSectionGroup(config);
if (serviceModel == null)
{
base.ApplyConfiguration();
return;
}
foreach (ServiceElement serviceElement in serviceModel.Services.Services)
{
this.LoadConfigurationSection(serviceElement);
return;
}
}
}
然后我称这个类为:
try
{
if (this._trfServiceHost == null)
this._trfServiceHost = new TRFServiceHost(typeof(TRFServerService));
if (this._trfServiceHost.State != CommunicationState.Opened)
{
this._trfServiceHost.Open();
message = "TRF Service has been turned on.";
}
}
catch (Exception e)
{
message = "TRF Service cannot be turned on. " + e.Message;
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="TRFServerModule.TRFServerService">
<endpoint address="" binding="netTcpBinding" contract="TRFCommonLibs.ITRFService"></endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:4530"/>
</baseAddresses>
</host>
</service>
</services>
配置文件如下所示:
try
{
if (this._trfServiceHost == null)
this._trfServiceHost = new TRFServiceHost(typeof(TRFServerService));
if (this._trfServiceHost.State != CommunicationState.Opened)
{
this._trfServiceHost.Open();
message = "TRF Service has been turned on.";
}
}
catch (Exception e)
{
message = "TRF Service cannot be turned on. " + e.Message;
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="TRFServerModule.TRFServerService">
<endpoint address="" binding="netTcpBinding" contract="TRFCommonLibs.ITRFService"></endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:4530"/>
</baseAddresses>
</host>
</service>
</services>
多谢各位