我已在我们的服务器上设置RESTful WCF Web服务(在Windows Server 2012 R2上运行的IIS 8.5)。我可以远程连接并运行暴露的方法没问题。 当方法包含与数据库的连接时,我遇到问题。尽管在IIS中设置了Windows身份验证,但是传递给数据库的用户名默认为计算机默认值,这是错误的。
我目前正在使用此web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<identity impersonate="true"/>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.serviceModel>
<services>
<service name="AriaRestFul2.Service1" behaviorConfiguration="AriaRestFul2.Service1Behavior">
<endpoint address="../Service1.svc" binding="webHttpBinding" contract="AriaRestFul2.IService1" behaviorConfiguration="webBehaviour" bindingConfiguration="restbinding">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange" bindingConfiguration="restbinding"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AriaRestFul2.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="restbinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<httpErrors errorMode="Detailed" />
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false"/>
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="AriaEntities" connectionString="metadata=res://*/Aria.csdl|res://*/Aria.ssdl|res://*/Aria.msl;provider=System.Data.SqlClient;provider connection string="data source=<instance>;initial catalog=Aria;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
我连接的数据库是通过EF6。我使用chrome作为客户端将URL传递给服务。我担心此设置可能需要在客户端的代码中分配凭据。如果是这种情况,我是否可以将服务配置为仅从浏览器传递当前用户?