Wcf MessageSecurityException:安全处理器无法在消息中找到安全标头

Wcf MessageSecurityException:安全处理器无法在消息中找到安全标头,wcf,web-services,ssl,xamarin.android,Wcf,Web Services,Ssl,Xamarin.android,Android安全WCF服务的Mono状态如何?到了SOAP1.2版本了吗? 我正在为一个Android应用程序编写一个POC,该应用程序将与WCF服务交互,但我很难让它正常工作 我正在尝试连接到具有TransportWithMessageCredential安全性的服务。然而,我在服务器端得到一个错误 这是服务器端错误: MessageSecurityException:安全处理器无法找到 消息中的安全标头。这可能是因为消息是 一个不安全的错误,或者因为 通信方。如果将服务配置为 安全性和客户

Android安全WCF服务的Mono状态如何?到了SOAP1.2版本了吗? 我正在为一个Android应用程序编写一个POC,该应用程序将与WCF服务交互,但我很难让它正常工作

我正在尝试连接到具有TransportWithMessageCredential安全性的服务。然而,我在服务器端得到一个错误

这是服务器端错误:

MessageSecurityException:安全处理器无法找到 消息中的安全标头。这可能是因为消息是 一个不安全的错误,或者因为 通信方。如果将服务配置为 安全性和客户端未使用安全性

服务器配置:

客户端代码:

公共课堂活动1:活动 { 私人按钮; 常量字符串地址=https://.../IngredientService.svc/BasicHttp; 受保护的重写void OnCreateBundle包 { base.OnCreatebundle; var timeout=新时间间隔0,1,0; var binding=new BasicHttpBindingBasicHttpSecurityMode.TransportWithMessageCredential { MessageEncoding=WSMessageEncoding.Text, 保安= { 运输= { ClientCredentialType=HttpClientCredentialType.None, ProxyCredentialType=HttpProxyCredentialType.None }, 信息= { ClientCredentialType=BasicHttpMessageCredentialType.UserName, } }, HostNameComparisonMode=HostNameComparisonMode.strong通配符, MaxReceivedMessageSize=655536, ReaderQuotas=new System.Xml.XmlDictionaryReaderQuotas { MaxArrayLength=655536, MaxStringContentLength=655536, }, SendTimeout=超时, OpenTimeout=超时, ReceiveTimeout=超时, }; System.Net.ServicePointManager.ServerCertificateValidationCallback+=OnServerCertificateValidationCallback; //从主布局资源设置视图 SetContentViewResource.Layout.Main; //从布局资源中获取我们的按钮, //并在其上附加一个事件 button=findViewBydResource.Id.MyButton; 按钮。单击+=委派 { client=new-IngredientServiceClientbinding,new-EndpointAddressaddress; var clientCredential=client.ClientCredentials.UserName; clientCredential.UserName=admin; clientCredential.Password=KDNSG7; client.BeginGetIngredientse,回调,null; }; } InCreditServiceClient客户端; 私有无效回调IAsyncResult ar { var result=client.EndGetIngredientsar; button.Text=result.First.Name; } 私有bool-OnServerCertificateValidationCallbackobject发送方,X509证书证书, X509链链,SslPolicyErrors SslPolicyErrors { 返回true; } }
此代码在WPF中运行良好,返回结果,一切正常。我从旧线程中看到WCF仍处于开发周期的早期,但我只想先检查一下我是否做错了什么。

要使您的服务在绑定不匹配的情况下仍能工作,您需要修改

<security mode="TransportWithMessageCredential" enableUnsecuredResponse="true"  >
   <message clientCredentialType="UserName" />
 </security>
我已经包含了上面示例中的整个webconfig以及添加的更改

 <service name="BrandDirector.ApplicationServer.Core.Services.UI.Products.Specifications.IngredientService" 
         behaviorConfiguration="CredentialValidation">
    <endpoint address="/BasicHttp"
        binding="basicHttpBinding"
        bindingConfiguration="BDBasicHttpBindingWithSecurity" 
        contract="BrandDirector.ApplicationServer.Core.Services.UI.Products.Specifications.IIngredientService" />
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>

<behavior name="CredentialValidation">
  <serviceMetadata httpGetEnabled="true" />
  <serviceDebug includeExceptionDetailInFaults="true" />
  <HttpStatusCode200Behavior />
  <serviceCredentials type="BrandDirector.ApplicationServer.Core.Security.Authentication.PasswordServiceCredentials, BrandDirector.ApplicationServer.Core.Security, Version=1.0.0.0, Culture=neutral">
    <userNameAuthentication userNamePasswordValidationMode="Custom"
      customUserNamePasswordValidatorType="BrandDirector.ApplicationServer.Core.Security.CredentialValidator, BrandDirector.ApplicationServer.Core.Security" />
  </serviceCredentials>
</behavior>

<extensions>
  <behaviorExtensions>
    <add name="HttpStatusCode200Behavior" type="BrandDirector.ApplicationServer.Core.Services.Common.ServiceModel.HttpStatusCode200BehaviorExtension, BrandDirector.ApplicationServer.Core.Services.Common" />
  </behaviorExtensions>

  <basicHttpBinding>
    <binding name="BDBasicHttpBindingWithSecurity" messageEncoding="Text" maxReceivedMessageSize="655536">
      <security mode="TransportWithMessageCredential" enableUnsecuredResponse="true"  >
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
</extensions>

要使服务在绑定不匹配的情况下仍能工作,您需要修改

<security mode="TransportWithMessageCredential" enableUnsecuredResponse="true"  >
   <message clientCredentialType="UserName" />
 </security>
我已经包含了上面示例中的整个webconfig以及添加的更改

 <service name="BrandDirector.ApplicationServer.Core.Services.UI.Products.Specifications.IngredientService" 
         behaviorConfiguration="CredentialValidation">
    <endpoint address="/BasicHttp"
        binding="basicHttpBinding"
        bindingConfiguration="BDBasicHttpBindingWithSecurity" 
        contract="BrandDirector.ApplicationServer.Core.Services.UI.Products.Specifications.IIngredientService" />
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>

<behavior name="CredentialValidation">
  <serviceMetadata httpGetEnabled="true" />
  <serviceDebug includeExceptionDetailInFaults="true" />
  <HttpStatusCode200Behavior />
  <serviceCredentials type="BrandDirector.ApplicationServer.Core.Security.Authentication.PasswordServiceCredentials, BrandDirector.ApplicationServer.Core.Security, Version=1.0.0.0, Culture=neutral">
    <userNameAuthentication userNamePasswordValidationMode="Custom"
      customUserNamePasswordValidatorType="BrandDirector.ApplicationServer.Core.Security.CredentialValidator, BrandDirector.ApplicationServer.Core.Security" />
  </serviceCredentials>
</behavior>

<extensions>
  <behaviorExtensions>
    <add name="HttpStatusCode200Behavior" type="BrandDirector.ApplicationServer.Core.Services.Common.ServiceModel.HttpStatusCode200BehaviorExtension, BrandDirector.ApplicationServer.Core.Services.Common" />
  </behaviorExtensions>

  <basicHttpBinding>
    <binding name="BDBasicHttpBindingWithSecurity" messageEncoding="Text" maxReceivedMessageSize="655536">
      <security mode="TransportWithMessageCredential" enableUnsecuredResponse="true"  >
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
</extensions>

我只使用了RestSharp和一个自定义身份验证头内容,该内容将在服务器端进行身份验证。

我只使用了RestSharp和一个自定义身份验证头内容,该内容将在服务器端进行身份验证。

此时MonoTouch不支持WS-Security协议,它允许客户端在SOAP消息信封内发送凭据。但是,MonoTouch确实支持通过指定适当的ClientCredentialType向服务器发送HTTP基本身份验证凭据

见本页:

此时,MonoTouch不支持WS-Security协议,该协议允许客户端在SOAP消息信封内发送凭据。但是,MonoTouch确实支持通过指定适当的ClientCredentialType向服务器发送HTTP基本身份验证凭据

见本页:

在我的例子中,在主机配置文件中的audienceUris标记中添加服务修复了该问题,但出现了相同的异常

<system.identityModel>
...
    <identityConfiguration>
    ...
        <audienceUris>
            <add value="serviceName.svc" />
        </audienceUris>
    ...
    </identityConfiguration>
...
</system.identityModel>

在我的例子中,将服务添加到audienceUris标记中 主机配置文件修复了该问题,但出现了相同的异常

<system.identityModel>
...
    <identityConfiguration>
    ...
        <audienceUris>
            <add value="serviceName.svc" />
        </audienceUris>
    ...
    </identityConfiguration>
...
</system.identityModel>

请注意,enableUnsecuredResponse不适用于basicHttpBinding。不过,它可以在customBinding上工作。请注意,enableUnsecuredResponse不能在basicHttpBinding上工作。不过,它在customBinding上起作用。