开发者

WCF with Windows Phone 7: Sending username over transport

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 b开发者_StackOverflow中文版elow. 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..


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜