积极答复者
广域网调用WCF报错:调用方未由服务进行身份验证

问题
答案
全部回复
-
客户端和服务端的绑定里 都要配置。
而且要应用到EndPoint的 绑定配置上
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum -
把你的配置文件贴出来看看
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum -
你好:我的服务端配置文件如下:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="NoneSecurity" maxBufferPoolSize="12000000" maxReceivedMessageSize="12000000" useDefaultWebProxy="false"> <readerQuotas maxStringContentLength="12000000" maxArrayLength="12000000"/> <security mode="None"> </security> </binding> </wsHttpBinding> </bindings> <services> <service name="YHW.LotteryServer.LotteryReport" behaviorConfiguration="LotteryServer.Service1Behavior"> <host> <baseAddresses> <add baseAddress = "http://localhost:8731/LotteryServer/" /> </baseAddresses> </host> <endpoint address ="" binding="wsHttpBinding" contract="YHW.LotteryServer.ILotteryReport" bindingConfiguration="NoneSecurity"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="LotteryServer.Service1Behavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
服务启动代码:
var lotteryService = new ServiceHost(typeof(LotteryServer.LotteryReport)); lotteryService.Open();
客户端配置文件:
<configuration> <configSections> </configSections> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_ILotteryReport" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="None"> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://localhost:8731/LotteryServer/" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ILotteryReport" contract="ReportReceiveService.ILotteryReport" name="WSHttpBinding_ILotteryReport"> <identity> <dns value="localhost" /> </identity> </endpoint> </client> </system.serviceModel> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
客户端调用代码:
WSHttpBinding binding = new WSHttpBinding("WSHttpBinding_ILotteryReport"); EndpointAddress address = new EndpointAddress(currentReceiver.ReceiverHost);//currentReceiver.ReceiverHost是由客户根据情况设好的服务端地点,没有问题的 ChannelFactory<ILotteryReport> factory = new ChannelFactory<ILotteryReport>(binding, address); ILotteryReport channel = factory.CreateChannel();
-
版主,顺便说一下我的测试经过:
我的客户端用我自己的电脑,win7操作系统。我的服务端交给我远方一个朋友那里,win server2003操作系统。
首先,当<security mode="Message">测试的时候,就报“调用方未由服务进行身份验证”这个错误。后来查到一篇文章提到,只要客户端操作系统管理员的密码与服务端的操作系统管理员密码一致,就可正常运行。我试了果然如此。但这样做显然没有意义,所以就改成<security mode="None">,就报EndpointIdentity错,再检查了一下代码应该是客户端创建信道有问题(见上次贴上的代码最后那块),于是又把这块代码改为:
EndpointAddress address = new EndpointAddress(currentReceiver.ReceiverHost); ChannelFactory<ILotteryReport> factory = new ChannelFactory<ILotteryReport>("WSHttpBinding_ILotteryReport"); factory.Endpoint.Address = address; ILotteryReport channel = factory.CreateChannel();
连接正常了,可发觉调用方法时从客户端传过去的对象参数都是null的。
搞来搞去没办法,叫朋友那边通过外网地址测试,竟然什么问题都没有,我不敢相信,他还拿到邻居的电脑测试,也行。而且,我给他的客户端配置是用默认的<security mode="Message">,服务端无论用“Message”还是“None“都行。
我真晕了,感觉这里跟很多因素有关,如操作系统、操作系统用户的帐号及权限、甚至所处的网络。请问是这样吗?既然有这么多不稳定因素,那么在做需要通过Internet传输的WCF的时候,比较安全可靠的做法是怎样呀?
恳求指点,先谢了。