2012-04-19 111 views
1

最近,我一直在研究WCF SOAP web服务,该服务由OAuth通过IIS7上托管的DotNetOpenAuth web服务保护。我很高兴地说我已经有了这个项目,也就是说,它可以在http上运行。将web服务从http移动到https

下一步是将两个项目(消费者和服务提供者,后者包含Web服务)移动到https。但是这造成了一些麻烦。

从客户端调用DataApi.svc时,出现以下错误;

Server Error in '/consumerexample/v2' Application. 
-------------------------------------------------------------------------------- 

The username is not provided. Specify username in ClientCredentials. 
Description: An unhandled exception occurred during the execution of the current web request.  Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The username is not provided. Specify username in ClientCredentials. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[InvalidOperationException: The username is not provided. Specify username in ClientCredentials.] 
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4727747 
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725 
OAuthConsumer.SampleServiceProvider.IDataApi.retrieveTimeTable(String weekVan, String weekTot) +0 
OAuthConsumer.SampleServiceProvider.DataApiClient.retrieveTimeTable(String weekVan, String weekTot) in C:\Program Files\TimeTableWebService\consumer\OAuthConsumer\Service References\SampleServiceProvider\Reference.cs:108 
OAuthConsumer.<>c__DisplayClass6.<retrieveTimeTable_Click>b__5(DataApiClient client) in C:\Program Files\TimeTableWebService\consumer\OAuthConsumer\GetTimeTable.aspx.cs:76 
OAuthConsumer.GetTimeTable.CallService(Func`2 predicate) in C:\Program Files\TimeTableWebService\consumer\OAuthConsumer\GetTimeTable.aspx.cs:129 
OAuthConsumer.GetTimeTable.retrieveTimeTable_Click(Object sender, EventArgs e) in C:\Program Files\TimeTableWebService\consumer\OAuthConsumer\GetTimeTable.aspx.cs:76 
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707 

-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237 

在http上,这个功能就像一个魅力。当我在本地调试用户时,整个OAuth授权工作得非常好。只有当我的DataApi.svc中的方法retrieveTimeTable被调用时,我收到这个错误。

在IIS7上,我为消费者和服务提供商网站启用了匿名和基本身份验证。 web.config文件如下所示;

消费者

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <binding name="WSHttpBinding_IDataApi" 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="999999999" 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="Transport"> 
    <transport clientCredentialType="Basic" proxyCredentialType="None" realm=""/> 
    <message clientCredentialType="Certificate" algorithmSuite="Default" /> 
     </security>   

     </binding> 
    </wsHttpBinding> 
    </bindings> 

    <client> 
    <endpoint address="https://websrv.hszuyd.nl/serviceprovider/v2/DataApi.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataApi" contract="SampleServiceProvider.IDataApi" name="WSHttpBinding_IDataApi"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint>   
    </client> 
</system.serviceModel> 

服务提供商

<system.serviceModel> 
    <behaviors> 
    <endpointBehaviors> 
     <behavior name="DataApiBehavior"> 
     <webHttp /> 
     </behavior> 
     <behavior name="wsHttpEnablingBehaviour"> 
     <webHttp/> 
     </behavior> 
    </endpointBehaviors>    

    <serviceBehaviors> 
     <behavior name="DataApiBehavior"> 
     <serviceMetadata httpsGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <serviceAuthorization serviceAuthorizationManagerType="OAuthServiceProvider.Code.OAuthAuthorizationManager, OAuthServiceProvider" principalPermissionMode="Custom" /> 
     </behavior> 
     <behavior name="wsHttpEnablingBehaviour"> 
     <serviceMetadata httpsGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

    <bindings> 
    <wsHttpBinding> 
     <binding name="wsHttpBinding" maxReceivedMessageSize="999999999"> 
     <security mode="Transport"> 
      <transport clientCredentialType="Basic" />  
     </security> 
     </binding>    
    </wsHttpBinding> 
    </bindings> 
    <services> 
    <service behaviorConfiguration="DataApiBehavior" name="OAuthServiceProvider.DataApi"> 
     <clear/> 
     <endpoint address="" binding="wsHttpBinding" contract="OAuthServiceProvider.Code.IDataApi" name="Oauth" bindingConfiguration="wsHttpBinding" />    
    </service> 
    </services> 
</system.serviceModel> 

的思考?

回答

0

可能您的消费者方使用一些代理来调用提供程序,但不指定基本身份验证所需的用户/传递。

+0

感谢您的快速回复!不过,我应该指出,消费者和服务提供商都在同一台服务器上。事实上,他们是在同一个IIS7网站中的两个独立的应用程序,我相信这意味着没有代理。如果我错了,请纠正我。 – Nico 2012-04-19 14:28:43

+0

我不会在http代理上谈论,而是在wcf代理上。在消费者的某个地方,你有像p = new ProviderService()这样的东西; p.Call()。您需要在p.ClientCredentials.UserName.User和Password中指定认证详细信息 – 2012-04-19 15:00:18

0

对不起,但我不明白。客户端不应该使用基本身份验证。基本身份验证只能用于Authorize.aspx页面。所以我认为问题在于web服务本身使用基本身份验证而不是oauth,但现在我不知道如何解决这个问题。如果我删除绑定=“wsHttpBinding”的端点是行不通的。 (我是Nico的同事)