[System.ServiceModel.ServiceContract]
public interface ICalculatorScient:ICalculator //为了恢复层级关系,修改客户端的代码,我使用的是接口继承
{
[System.ServiceModel.OperationContract]
int Multiply(int x, int y);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface ICalculatorScientChannel : WCFClient.MyService.ICalculatorScient, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class CalculatorScientClient : System.ServiceModel.ClientBase<WCFClient.MyService.ICalculatorScient>, WCFClient.MyService.ICalculatorScient
{
public CalculatorScientClient() {
}
public CalculatorScientClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public CalculatorScientClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public CalculatorScientClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public CalculatorScientClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public int Multiply(int x, int y)
{
return Channel.Multiply(x,y);
}
public int Add(int x, int y)
{
return Channel.Add(x,y);
}
}
[System.ServiceModel.ServiceContract]
public interface ICalculator //这是父接口,通过另外一个借口来继承,实现WCF继承关系
{
[System.ServiceModel.OperationContract]
int Add(int x, int y);
}
public partial class Calculator : System.ServiceModel.ClientBase<ICalculator>, ICalculator
{
public int Add(int x, int y)
{
return Channel.Add(x,y);
}
}
-------------------------------------------------------------------------------------------------------
客户端配置文件的修改内容如下
<client>
<endpoint address="http://localhost:8080/MyCalculator/" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ICalculatorScient" contract="MyService.ICalculatorScient"
name="WSHttpBinding_ICalculatorScient">
<identity>
<userPrincipalName value="WWW-9A159746699\Administrator" />
</identity>
</endpoint>
<endpoint address="http://localhost:8080/MyCalculator/" binding="wsHttpBinding" contract="MyService.ICalculator" name="CalculatorClient">
</endpoint>
</client>
---------------------------------------------------------------------------------------------------------
未处理的异常: System.ServiceModel.AddressAlreadyInUseException: HTTP 无法注册 U
RL http://+:8080/MyCalculator/。另一应用程序已使用 HTTP.SYS 注册了该 URL。 --->
System.Net.HttpListenerException: 在前缀“http://+:8080/MyCalculator/”上侦听失
败,因为它与计算机上的现有注册冲突。
在 System.Net.HttpListener.AddAll()
在 System.Net.HttpListener.Start()
在 System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
--- 内部异常堆栈跟踪的结尾 ---
在 System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
在 System.ServiceModel.Channels.TransportManager.Open(TransportChannelListene
r channelListener)
在 System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTranspor
tManagersCallback selectTransportManagerCallback)
在 System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan time
out)
在 System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Channels.DatagramChannelDemuxer`2.OnOuterListenerOpen(
ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout)
在 System.ServiceModel.Channels.SingletonChannelListener`3.OnOpen(TimeSpan ti
meout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Security.NegotiationTokenAuthenticator`1.OnOpen(TimeSp
an timeout)
在 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(Tim
eSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator
.Open(TimeSpan timeout)
在 System.ServiceModel.Security.SecurityUtils.OpenTokenAuthenticatorIfRequire
d(SecurityTokenAuthenticator tokenAuthenticator, TimeSpan timeout)
在 System.ServiceModel.Security.SecurityProtocolFactory.Open(String propertyN
ame, Boolean requiredForForwardDirection, SecurityTokenAuthenticator authenticat
or, TimeSpan timeout)
在 System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeS
pan timeout)
在 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(Tim
eSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Security.SecurityProtocolFactory.Open(Boolean actAsIni
tiator, TimeSpan timeout)
在 System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(
TimeSpan timeout)
在 System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan tim
eout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnO
pen(TimeSpan timeout)
在 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(Tim
eSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator
.Open(TimeSpan timeout)
在 System.ServiceModel.Security.SecurityUtils.OpenTokenAuthenticatorIfRequire
d(SecurityTokenAuthenticator tokenAuthenticator, TimeSpan timeout)
在 System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan
timeout)
在 System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(Tim
eSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(
TimeSpan timeout)
在 System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan tim
eout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Open()
在 WCFHost.Program.Main(String[] args) 位置 F:\ASP.NET\WCFHost\WCFHost\Progra
m.cs:行号 18
未处理的异常: System.ServiceModel.CommunicationObjectFaultedException: 通信对象
System.ServiceModel.ServiceHost 无法用于通信,因为其处于“出错”状态。
在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
在 System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose()
在 WCFHost.Program.Main(String[] args) 位置 F:\ASP.NET\WCFHost\WCFHost\Progra
m.cs:行号 20
请按任意键继续. . .