C# Wcf联合(服务不支持内容类型application/soap+;xml;charset=utf-8)

C# Wcf联合(服务不支持内容类型application/soap+;xml;charset=utf-8),c#,wcf,iis-7.5,wif,ws-federation,C#,Wcf,Iis 7.5,Wif,Ws Federation,我有活动的WCF STS服务(实现了microsoft.identity…securitytokenservice),用于通过SQL db(无aspnetdb,无成员身份)对用户进行身份验证 配置如下: <service name="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract" behaviorConfiguration="srvBehavior"> <endpoint addre

我有活动的WCF STS服务(实现了microsoft.identity…securitytokenservice),用于通过SQL db(无aspnetdb,无成员身份)对用户进行身份验证

配置如下:

  <service name="Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract" behaviorConfiguration="srvBehavior">
    <endpoint address="" binding="ws2007HttpBinding" bindingConfiguration="ws2007Http" contract="Microsoft.IdentityModel.Protocols.WSTrust.IWSTrust13SyncContract" >
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service> 
<behavior name="srvBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceCredentials useIdentityConfiguration="false">
        <serviceCertificate findValue="MySelfSignedCert" storeLocation="LocalMachine" storeName="My" x509FindType="FindByIssuerName"/>
      </serviceCredentials>
      <serviceAuthorization principalPermissionMode="Always" />
    </behavior>
<ws2007HttpBinding>
    <binding name="ws2007Http" messageEncoding="Mtom">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" establishSecurityContext="false" negotiateServiceCredential="false"/>
      </security>
    </binding>
  </ws2007HttpBinding>
<protocolMapping>
  <add binding="ws2007HttpBinding" scheme="https" bindingConfiguration="ws2007Http" />
  <add binding="wsHttpBinding" scheme="http" bindingConfiguration="securityBinding" />
</protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
内部异常

Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost/FederationSample/TestService/Service1.svc.  The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
我知道,最流行的原因是消息版本,但我使用
ws2007Http
ws2007FederatedHttp
。好的,两个绑定都使用soap12。
有人能解释一下吗

<microsoft.identityModel>
<service>
  <audienceUris>
    <add value="http://localhost/FederationSample/TestService/Service1.svc" />
  </audienceUris>
  <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
    <trustedIssuers>
      <add thumbprint="d7ad4ffb08143745134b95607cde1cb0fdcc0366" name="CustomSTS" />
    </trustedIssuers>
  </issuerNameRegistry>
  <claimsAuthorizationManager type="TestService.CustomClaimsAuthorizationManager, TestService" />
  <serviceCertificate>
    <certificateReference x509FindType="FindByThumbprint" findValue="d7ad4ffb08143745134b95607cde1cb0fdcc0366" />
  </serviceCertificate>
  <certificateValidation certificateValidationMode="None" />
  <federatedAuthentication>
    <cookieHandler requireSsl="false" />
  </federatedAuthentication>
</service>
var identity = new X509CertificateEndpointIdentity(FederationUtilities.LookupCertificate(StoreName.Root, StoreLocation.LocalMachine, "MySelfSignedCert"));
var token = SecurityProxy.RequestSecurityToken(new EndpointAddress(new Uri("https://localhost/TokenIssuer/STS.svc"), identity), new Uri("http://localhost/FederationSample/TestService/Service1.svc"));
rsult = CallService<T>(token, new Uri("http://localhost/FederationSample/TestService/Service1.svc"));

public static SecurityToken RequestSecurityToken(EndpointAddress idpAddress, Uri serviceAddress)
    {
        var factory = new WSTrustChannelFactory(new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), idpAddress)
            {
                TrustVersion = TrustVersion.WSTrust13,
            };

        factory.Credentials.UserName.UserName ="admin";
        factory.Credentials.UserName.Password = "qDJ9SknUYxYx0JCnIpfY10kzejDm6wQWvTZVtx42SBs=";
        factory.Credentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByIssuerName, "MySelfSignedCert");
        factory.Credentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByIssuerName, "MySelfSignedCert");
        factory.ConfigureChannelFactory();
        var rst = new RequestSecurityToken
        {
            RequestType = RequestTypes.Issue,
            KeyType = KeyTypes.Symmetric,
            AppliesTo = new EndpointReference(serviceAddress.AbsoluteUri),
        };
        var token = factory.CreateChannel().Issue(rst);
        return token;
    }

public static T CallService<T>(SecurityToken token, Uri serviceAddress)
    {
        var identity = new X509CertificateEndpointIdentity(FederationUtilities.LookupCertificate(StoreName.Root, StoreLocation.LocalMachine, "MySelfSignedCert"));
        var binding = new WS2007FederationHttpBinding("wsFed");

        var factory = new ChannelFactory<T>(binding, new EndpointAddress(serviceAddress, identity));
        factory.Credentials.SupportInteractive = false;
        factory.Credentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByIssuerName, "MySelfSignedCert");
        factory.Credentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.Root, X509FindType.FindByIssuerName, "MySelfSignedCert");
        factory.ConfigureChannelFactory();

        return  factory.CreateChannelWithIssuedToken(token);
    }
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost/FederationSample/TestService/Service1.svc.  The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..