WCF中客户端恢复继承层级关系,高手帮忙解决一下

hechenqingtian 2009-08-06 01:53:10

[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
请按任意键继续. . .
...全文
234 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hechenqingtian 2009-08-14
  • 打赏
  • 举报
回复
8080 端口是什么,tomcat 的,我机器上都没有装这些东西 怎么会占用,你们说的都错了,不是这样的。你们没有将WCF 搞清楚,不过还是谢谢你们啊。这个问题是由IIS 本事问题引起的,至于怎么解决我就不知道了,如果知道的话可以告诉我 我的QQ 821865130, .net 讨论群88718955
再出发666 2009-08-06
  • 打赏
  • 举报
回复

<endpoint address="http://localhost:8080/MyCalculator/" binding="wsHttpBinding" contract="MyService.ICalculator" name="CalculatorClient">

8080这么常用的不要用在wcf服务上,换个
souperstar 2009-08-06
  • 打赏
  • 举报
回复
换个端口吧~~
zdl110110 2009-08-06
  • 打赏
  • 举报
回复
8080端口貌似被占用,换个吧
地下室小红叔 2009-08-06
  • 打赏
  • 举报
回复
貌似在同一机器上调试使用了相同端口

将client的配置端口改一下试试
zhulong1111 2009-08-06
  • 打赏
  • 举报
回复
顶下 啊
xunis 2009-08-06
  • 打赏
  • 举报
回复
去零回答的第一页的倒数第六个回答下 送你50分 要结贴了 速度啦

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧