以下代码所需的WCF自定义绑定配置文件

时间:2013-01-08 13:32:43

标签: wcf biztalk

需要在BizTalk发送端口中导入自定义绑定配置文件以获取以下代码段。

我无法在配置文件中的绑定元素上添加用户名UserNameSecurityTokenParameters,但可能是programaticaly。

必需的SOAP标头是

<s:Header>
        <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
     <u:Timestamp u:Id="uuid-9e629b43-b7be-498b-9cf6-03ee8a54c0d0-1">
        <u:Created>2013-01-08T10:35:11.554Z</u:Created>
        <u:Expires>2013-01-08T10:40:11.554Z</u:Expires>
     </u:Timestamp>
     <o:BinarySecurityToken u:Id="uuid-85871719-c001-4435-82dd-a229d1f93b9d-3" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MIIEijCCA3KgAwIBAgIOAQAAAAABO0dvgccW+zwwDQYJKoZIhvcNAQEFBQAwQDEXMBUGA1UEChMOQ3liZXJ0cnVzdCBJbmMxJTAjBgNVBAMTHEN5YmVydHJ1c3QgU3VyZWNyZWRlbnRpYWwgQ0EwHhcNMTIxMTI4MTQzNzE0WhcNMTMxMTI4MTQzNzE0WjB+MQswCQYDVQQGEwJVUzEjMCEGA1UEChMaTkVDIENvcnBvcmF0aW9uIG9mIEFtZXJpY2ExJTAjBgkqhkiG9w0BCQEWFmJpamkuc3VrdW1hckBuZWNhbS5jb20xIzAhBgNVBAMTGk5FQyBDb3Jwb3JhdGlvbiBvZiBBbWVyaWNhMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAob9NweUoFvfH+fvTJk6xitNvCjYN+Yev4tpUAqBcz3Y0RgzySrdf2cZzRd0j53R2Q98KEgkVXAdfR8yBvOpUVljpNSRvwNT8TYl9MN/giiH6hQUPTli9mq+tNuplT71soeTL/3RbVRzNWdhdZn8itV9Bte8nAKnub4lApgh1QLub2uUfxqYWOo2jz5t4ADxGohGfS7lJgincWIsqDGtf2vYu33SppFhyhAtINRMmP35a2S2aB/ynS+MRdP053Gc5OIh3jjQE/mMWQjHHu4lXFHJiImkhuv6ZGoUzVx2J8jyi9jqOz9wBw8xqC+ch+GU2hME/eDoTxQy0vQy1CR/xNQIDAQABo4IBQjCCAT4wHwYDVR0jBBgwFoAUSUySC81KI7bOee6eVTNrWkTAApUwOwYDVR0fBDQwMjAwoC6gLIYqaHR0cDovL2NybC5vbW5pcm9vdC5jb20vU3VyZUNyZWRlbnRpYWwuY3JsMB0GA1UdDgQWBBSL1imayafzgtoV6/cjqcDTmvQ9IDAPBgNVHRMBAf8EBTADAgEAMA4GA1UdDwEB/wQEAwIE8DARBglghkgBhvhCAQEEBAMCBaAwSQYIKwYBBQUHAQEEPTA7MDkGCCsGAQUFBzAChi1odHRwOi8vY2FjZXJ0Lm9tbmlyb290LmNvbS9zdXJlY3JlZGVudGlhbC5jcnQwIQYDVR0RBBowGIEWYmlqaS5zdWt1bWFyQG5lY2FtLmNvbTAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwQwDQYJKoZIhvcNAQEFBQADggEBAERfT+KyQiDAeFisPfXeYvOGdqSefMJl133IYSve0xup47NoI0HL7UqW/y6bpUaZpXM4+slRzKK573jArUEzqV8sqmEyP/EF2tkJGFAfhQuSyxKDOBMTEII8O4OWKv7YxBMR+v2nm4noKotBXGnfbe3SON2kozHXCBlVB3btO1d/tj/js1bFFZ5+R1ihJobxRtW3GYint9LRdUvKdAqChWsh50/U1GmWgzY/Y2UE9I3mHy7JRdj+LU6iliPobdWZBZlFgEISItTjn2PrCZDXAUwtrMvztWBKurlsDzCn6Zu3U6TDKjzmfm1i+0hvJ7cnAAU8RQT4Bh/zfJG1sxTr98s=</o:BinarySecurityToken>
     <o:UsernameToken u:Id="uuid-85871719-c001-4435-82dd-a229d1f93b9d-1">
        <o:Username>WPG_NEC</o:Username>
        <o:Password o:Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">NECwsTw02</o:Password>
     </o:UsernameToken>
     <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
           <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
           <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
           <Reference URI="#_1">
              <Transforms>
                 <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </Transforms>
              <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
              <DigestValue>Jb40XGCX3BM23CUxONUtejfkd20=</DigestValue>
           </Reference>
           <Reference URI="#uuid-9e629b43-b7be-498b-9cf6-03ee8a54c0d0-1">
              <Transforms>
                 <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </Transforms>
              <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
              <DigestValue>UO1kn2g4oTLkiYoRWYtLa+q/ePo=</DigestValue>
           </Reference>
           <Reference URI="#uuid-85871719-c001-4435-82dd-a229d1f93b9d-1">
              <Transforms>
                 <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
              </Transforms>
              <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
              <DigestValue>97Q6wwswEhNLkHt7iyHEI5WzWU0=</DigestValue>
           </Reference>
        </SignedInfo>
        <SignatureValue>IUMg0j7HiWFHHHUI9OPu+kDCNMaaOVNX3JBg1/EabzDW3UMFAntb94xZ7nnf6zFOJHbMajUgMwt7yt26I/u+gynhLQlQeOKfDkFzyXrQeX1uYsTdBh88tDHBd8BdBdNaLzXtJB/G5D4b2kwXfrVaQlB3TqKPc84814aaNQaVuquuTkfR7Mj9VXRcDSswWVsHke7GxQeMyt/pg0mtzQnDO0oLzCVXKTLg3MuvQpD5JppMIbdxgMojs8y6GiTKvWRKOwgZXZ8Olab6SSZfz0/s59YvrPtioabafqsPKMGUGnzAUylNvcXM/bKxohWcI+dM+JGck55HzkMzHMzWnv6aFA==</SignatureValue>
        <KeyInfo>
           <o:SecurityTokenReference>
              <o:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid-85871719-c001-4435-82dd-a229d1f93b9d-3"/>
           </o:SecurityTokenReference>
        </KeyInfo>
     </Signature>
  </o:Security>

下面的代码是一个工作代码,但无法为下面的代码生成自定义绑定配置文件。因此无法使用BizTalk适配器。

此代码生成以上soap标头。我需要一个自定义绑定配置文件,以将其导入BizTalk发送端口。

 var b = new CustomBinding();
        var sec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
        var userNameToken = new UserNameSecurityTokenParameters();
        sec.EnableUnsecuredResponse = true;
        sec.EndpointSupportingTokenParameters.Signed.Add(userNameToken);
        sec.MessageSecurityVersion =
            MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        sec.IncludeTimestamp = true;
        sec.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
        sec.AllowInsecureTransport = true;
        b.Elements.Add(sec);
        b.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
        b.Elements.Add(new HttpsTransportBindingElement());
        var c = new ServiceReference1.taservicePortClient(b, new EndpointAddress(new Uri("https://abc.def.com:443/qwerty"), new DnsEndpointIdentity("ABC Corp of World"), new AddressHeaderCollection()));
        c.ClientCredentials.UserName.UserName = "Username";
        c.ClientCredentials.UserName.Password = "Pwd";
        c.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "42D01DCCBE1EF5F6C414E0869C21ED0EC86C9B88A");
        c.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "42D01DCCBE1EF5F6C414E0869C21ED0EC86C9B88A");
        ServiceReference1.taservicePort d = c;
        var e = new ServiceReference1.receiveRequest(input);
        ServiceReference1.receiveResponse res = d.receive(e);

1 个答案:

答案 0 :(得分:0)

在代码中创建自定义绑定时,WCF配置仅提供可用功能的子集。如果要在配置中使用新绑定,则必须创建新的绑定扩展名 - check BinaryOverHttpWithChaosBinding and following classes in this article