首页 > 代码库 > C#:Bug,EndpointDispatcher&ContractFilter

C#:Bug,EndpointDispatcher&ContractFilter

项目发布的时候,文件上传忽然出现一个问题,很古怪,问题描述如下:

Error:

StackTrace:

 

[FaultException:由于  ContractFilter EndpointDispatcher不匹配,因此 Actionhttp://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue的消息无法在接收方处理。这可能是由于协定不匹配(发送方和接收方 Action 不匹配)或发送方和接收方绑定/安全不匹配。请检查发送方和接收方是否具有相同的协定和绑定(包括安全要求,如 MessageTransportNone)]

   System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target) +5499790

   System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState) +49

 

[SecurityNegotiationException: Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. ]

   WHPT_WebApp.HanderOperater.HanderOperaterAddMuti.btn_import_Click(Object sender, ImageClickEventArgs e) in E:\GH_WHPT1210\WHPT_WebApp\HanderOperater\HanderOperaterAddMuti.aspx.cs:163

   System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115

   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +120

   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10

   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13

   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

[SecurityNegotiationException:无法打开安全通道因为安全协商远程终结点失败可能由于缺席不正确地指定EndpointIdentityEndpointAddress创建通道验证EndpointIdentity指定隐含EndpointAddress正确标识远程终结点]


属性值

类型:System.Boolean
如果通过协商过程获取服务凭据,则为 true;否则为false默认值为 true


MessageSecurityOverHttp.NegotiateServiceCredential 属性

NegotiateServiceCredential ="true"

获取或设置一个值,该值指示是在带外客户端提供服务凭据,还是通过协商过程从服务向客户端获取服务凭据。


属性设置为 true 需要客户端和服务支持 WS-Trust 和 WS-SecureConversation。将属性设置为false 时不需要 WS-Trust 或 WS-SecureConversation 受支持。

对于 Anonymous、Username 或 Certificate 客户端凭据类型,将此属性设置为false 意味着服务证书必须可用于带外客户端,并且客户端必须指定要使用的服务证书。

对于 Windows 凭据,将此属性设置为 false 将导致基于KerberosToken 的身份验证。这要求客户端和服务都是 Kerberos 域的一部分。 此模式可与实现 OASIS Kerberos 令牌配置文件的 SOAP 堆栈交互操作。将此属性为true 会引起通过 SOAP 消息进行 SPNego 交换的 SOAP 协商。此模式不可互操作。

此属性指示是否在客户端和服务之间自动协商服务凭据。 如果此属性为 true,则会进行此类协商。 如果此属性为 false,则在与服务进行通信之前,必须在客户端指定服务凭据。

如果将此属性设置为 false,并且将绑定配置为使用 Windows 作为客户端凭据类型,则必须将服务帐户与服务主体名称 (SPN) 相关联。为此,请在 NETWORK SERVICE 帐户或 LOCAL SYSTEM 帐户下运行服务。也可以使用 SetSpn.exe 工具为服务帐户创建一个 SPN。 不论何种情况,客户端都必须使用 <servicePrincipalName> 元素中的正确 SPN,或者通过使用EndpointAddress 构造函数来应用正确的 SPN。

WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType =
    MessageCredentialType.UserName;
binding.Security.Message.NegotiateServiceCredential = false;

CalculatorClient CalculatorClient = new CalculatorClient("myBinding");
CalculatorClient.ClientCredentials.ServiceCertificate.
    SetDefaultCertificate("Al", StoreLocation.CurrentUser, StoreName.My);

另外,发一下我的配置错误所在:

 <configuration>                                                                                                                  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IExcelService" 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="65536" 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="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
             realm="" />
            <message clientCredentialType="Windows" negotiateServiceCredential="true"
             algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/ExcelService.svc" binding="wsHttpBinding"
      bindingConfiguration="WSHttpBinding_IExcelService" contract="ExcelService.IExcelService"
      name="WSHttpBinding_IExcelService">
        <identity>
          <dns value=http://www.mamicode.com/"localhost" />>

PS:此文仅供记录交流,不做它用






C#:Bug,EndpointDispatcher&ContractFilter