![](/img/trans.png)
[英]Impersonation using a self-hosted WCF WebServiceHost gets 'An operations error occurred.' error
[英]Impersonation in self-hosted WCF?
我目前正在使用自托管 SL Svc模板開發自托管在 Windows 服務中的 WCF 服務。 該模板可以正常工作,並且我可以從我的 Silverlight 應用程序進行調用,但是當我嘗試修改項目以使用模擬時:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
它在host.Open();
:
System.InvalidOperationException 未處理消息=合同操作“GetData”需要 Windows 身份才能自動模擬。 代表調用者的 Windows 身份不是由合同('IService1','http://tempuri.org/'的綁定('CustomBinding','http://tempuri.org/')提供的。
這是我的配置:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service name="SLServiceLibrary.Service1" behaviorConfiguration="SLServiceLibrary.ServiceBehavior">
<endpoint address="Service1" binding="customBinding" contract="SLServiceLibrary.IService1" bindingConfiguration="binaryHttpBinding"/>
<endpoint address="" binding="webHttpBinding" contract="SLServiceLibrary.IClientAccessPolicy" behaviorConfiguration="webHttpEnablingBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SLServiceLibrary.ServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpEnablingBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
我必須改變什么才能完成這項工作? 我是否也需要向我的 Silverlight 客戶端添加一些配置?
提前致謝:)
經過長時間的搜索,我想出了兩個解決方案,一個是在MSDN找到的:
<bindings>
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding/>
<httpTransport authenticationScheme="Ntlm"/>
</binding>
</customBinding>
</bindings>
另一個是在Silverlight 論壇上:
<bindings>
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding/>
<httpTransport authenticationScheme="Negotiate"/>
</binding>
</customBinding>
</bindings>
不知道這兩者之間的主要區別是什么,我已經成功打開服務並從 Silverlight 調用它。 如果有人打電話詳細說明差異,我將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.