2012-04-19 101 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的同事)