WCF 出錯的解決方法

1. 運行self-hosting以後報錯:安全

                System.ServiceModel.AddressAccessDeniedException' occurred in System.Servic url

                System.ServiceModel.AddressAccessDeniedException: ... http://+:9999/calculatorService/...spa

以管理員權限運行cmd,解決HTTP名字空間保護的問題。打開了cmd以後,運行orm

"netsh http add urlacl http://+:9999/calculatorService/ user=everyone"rem

2. get

    System.ServiceModel.CommunicationObjectFaultedExceptioncmd

    The communication object, System.ServiceModel.ServiceHost, cannot be used for communication it

而且查看stack 中顯示 timeout,猜測估計是權限不夠,重啓vs,右擊選擇屬性->兼容性->以管理員身份運行。 io

成功form

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的,須要在服務端要打開端口號,在防火牆中新增規則。

相關文章
相關標籤/搜索