1. 运行self-hosting之后报错:
System.ServiceModel.AddressAccessDeniedException' occurred in System.Servic
System.ServiceModel.AddressAccessDeniedException: ... http://+:9999/calculatorService/...
以管理员权限运行cmd,解决HTTP名字空间保护的问题。打开了cmd之后,运行
"netsh http add urlacl http://+:9999/calculatorService/ user=everyone"
2.
System.ServiceModel.CommunicationObjectFaultedException
The communication object, System.ServiceModel.ServiceHost, cannot be used for communication
并且查看stack 中显示 timeout,猜想估计是权限不够,重启vs,右击选择属性->兼容性->以管理员身份运行。
成功
3.
'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll
Additional information: SOAP security negotiation with 'http://xlt1159-cn1:9999/messageService' for target 'http://xlt1159-cn1:9999/messageService' failed. See inner exception for more details.
问题:WCF的安全问题,如果不需要考虑安全性,最简单的方法将security.mode 设置为Node。
如在service中添加代码:
WSHttpBinding wsb = new WSHttpBinding();
wsb.Name = "TestBinding";
wsb.Security.Mode = SecurityMode.None;
在 client中添加代码:
WSHttpBinding wsb = new WSHttpBinding();
wsb.Name = "TestBinding";
wsb.Security.Mode = SecurityMode.None;
wsb.Security.Message.ClientCredentialType = MessageCredentialType.None;
(https://msdn.microsoft.com/en-us/library/ms731925.aspx)
4. WCF服务端如果是remote的,需要在服务端要打开端口号,在防火墙中新增规则。