WCF 与 Windows Phone 7:通过传输发送用户名
我已经创建了一个支持 Silverlight 的 WCF 服务,使用自定义绑定来按照准则传输二进制消息。 通过添加 httpsTransport 条目并在本地 IIS 实例上安装 Verisign CA,我可以从手机模拟器通过 https 调用此服务。到目前为止,一切都很好。
我将安全条目添加到绑定中,并将服务凭证添加到行为中以使用自定义类。当通过客户端代理提交有效的用户名/密码对时,此服务和自定义类在单元测试中工作正常。
当我从 WP7 模拟器执行相同操作时,我收到“MessageSecurityException”。
我的服务配置如下。关于如何调试的任何想法或指示?谢谢...
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SimpleService.Simple.customBinding0">
<security authenticationMode="UserNameOverTransport"/>
<binaryMessageEncoding />
<httpsTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service name="SimpleService.Simple">
<endpoint address="" binding="customBinding" bindingConfiguration="SimpleService.Simple.customBinding0"
contract="SimpleService.Simple" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SimpleService.MyValidator,SimpleService"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
再次谢谢..
I have created a Silverlight-enabled WCF service using a custom binding to transmit binaryMessages as per guidelines.
I was able to call this service over https from the phone emulator by adding the httpsTransport entry and installing a Verisign CA on my local IIS instance. So far so good.
I added the security entry to the binding and the service credentials to the behavior to use a custom class. This service and custom class works fine from unit test when a valid username/password pair is submitted via the client proxy.
When I do the same from the WP7 emulator, I get a "MessageSecurityException".
My service config is below. Any ideas or pointers on how to debug? Thanks...
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SimpleService.Simple.customBinding0">
<security authenticationMode="UserNameOverTransport"/>
<binaryMessageEncoding />
<httpsTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service name="SimpleService.Simple">
<endpoint address="" binding="customBinding" bindingConfiguration="SimpleService.Simple.customBinding0"
contract="SimpleService.Simple" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SimpleService.MyValidator,SimpleService"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thanks again..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢我的同事 Yossi Dahan,我能够使用 Visual Studio 中的 WCF 服务配置编辑器将跟踪添加到服务的 Web.config,然后使用 Microsoft 服务跟踪查看器来分析日志。
这表明请求已到达服务器,但自定义验证器抛出异常。
通过从 VS 内连接到 IIS,我能够调试自定义验证器以发现(令人尴尬地)我的 WP7 测试正在传递无效的用户凭据 - 所以一切正常!
经验教训 - 在使用新技术时找到正确的跟踪/工具。
With thanks to my colleague, Yossi Dahan, I was able to use the WCF Service Configuration Editor in Visual Studio to add tracing to my Web.config for the service and then use the Microsoft Service Trace Viewer to analyse the logs.
This indicated that the request was getting through to the server but the custom validator was throwing an exception.
By attaching to IIS from within VS I was able to debug the custom validator to discover (embarrasingly) that my WP7 test was passing invalid user credentials - so everything was working correctly!
Lesson learned - get the right tracing/tooling in place when working with new tech.