none
how to create custombinding like what i expect? RRS feed

  • 问题

  • The soap request was not same to the one used app.config when I used custom binding by program,my program was like this:
            static Binding myCustomBinding()
            {
                HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
    
                SecurityBindingElement messageSecurity = SecurityBindingElement.CreateMutualCertificateBindingElement();
    
                messageSecurity.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12;
                messageSecurity.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic128Rsa15;
                //messageSecurity.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
                messageSecurity.IncludeTimestamp = true;
                messageSecurity.EnableUnsecuredResponse = true;
    
                TextMessageEncodingBindingElement tmee = new TextMessageEncodingBindingElement();
                tmee.MaxReadPoolSize = 64;
                tmee.MaxWritePoolSize = 16;
                tmee.MessageVersion = MessageVersion.Soap11WSAddressing10;
                tmee.WriteEncoding = Encoding.UTF8;
                tmee.ReaderQuotas.MaxDepth = 32;
                tmee.ReaderQuotas.MaxStringContentLength = 8192;
                tmee.ReaderQuotas.MaxArrayLength = 16384;
                tmee.ReaderQuotas.MaxBytesPerRead = 4096;
                tmee.ReaderQuotas.MaxNameTableCharCount = 16384;
    
                return new CustomBinding(messageSecurity,tmee, httpTransport);
            }
    
        
    the app.config was:
          <customBinding>
            <binding name="myCustomBinding" >          
              <textMessageEncoding messageVersion="Soap11"/>                     
              <security   enableUnsecuredResponse="true" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
                          defaultAlgorithmSuite="Basic128Rsa15" authenticationMode="MutualCertificate" messageProtectionOrder="SignBeforeEncrypt"
                          requireDerivedKeys="false" includeTimestamp="true" requireSecurityContextCancellation="false">
                <secureConversationBootstrap />
              </security>
              <httpTransport/>
            </binding>
          </customBinding>
    
       
    the soap request made by program:
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    	<s:Header>
    		<a:Action s:mustUnderstand="1" u:Id="_4">DescribeInstances</a:Action>
    		<a:MessageID u:Id="_5">urn:uuid:59f746da-8dc5-407c-a992-858b92e0c0d4</a:MessageID>
    		<a:ReplyTo u:Id="_6">
    			<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    		</a:ReplyTo>
    		<a:To s:mustUnderstand="1" u:Id="_7">http://192.137.70.10:8773/services/Eucalyptus</a:To>
    		<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-5c2b659b-cb39-49e7-8e89-d91aa7f7cc22-2">
    				<u:Created>2011-11-26T01:25:05.935Z</u:Created>
    				<u:Expires>2011-11-26T01:30:05.935Z</u:Expires>
    			</u:Timestamp>
    			<e:EncryptedKey Id="uuid-5c2b659b-cb39-49e7-8e89-d91aa7f7cc22-1" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
    				<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
    				<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    					<o:SecurityTokenReference>
    						<o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1">ti0Ll+NRWH4uY4T4UFK7SBR7ZrY=</o:KeyIdentifier>
    					</o:SecurityTokenReference>
    				</KeyInfo>
    				<e:CipherData>
    					<e:CipherValue>bqfc63PY1gi2X3J8x83fDxHnyMGlaB3wSIF0doRQ/Ho2ELXM8TppQCWPsPf95pmYm8+2eXbT0R+vqWiTGwp7Tcwbqb7LCFu33GpLB6D6bDB1bua55Y2CjYn5TlbdUNHwRjKvnEgkZIpBfRAyuWUjNemfR1UVUZWgSUgY9VD6TnMZeixTJdNaJZcSNCkB4eo3naCBOsQ5ZoIIDfoKJkIZdHZSI2LPb4sTBIv/iAepWT6YVpfCxwZDKEsTUnrNWz8dwzVKZANydBmZCXevvctB+slZh0Tr+nyREryDBUdhDZNcbmbHK25pjVn8ndAyVfeANYqMfzZ6QTC+JD86sQozsQ==</e:CipherValue>
    				</e:CipherData>
    			</e:EncryptedKey>
    			<sc:DerivedKeyToken u:Id="_0" xmlns:sc="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512">
    				<o:SecurityTokenReference>
    					<o:Reference URI="#uuid-5c2b659b-cb39-49e7-8e89-d91aa7f7cc22-1"/>
    				</o:SecurityTokenReference>
    				<sc:Offset>0</sc:Offset>
    				<sc:Length>16</sc:Length>
    				<sc:Nonce>X5UzGgkuNt1KnGCtW6riYA==</sc:Nonce>
    			</sc:DerivedKeyToken>
    			<o:BinarySecurityToken u:Id="uuid-9aae4e7c-5a25-4595-9ccc-d96758769583-1" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3">MIIDfTCCAmWgAwIBAgIGATOm1oQ+MA0GCSqGSIb3DQEBDQUAMHQxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNU2FudGEgQmFyYmFyYTEOMAwGA1UEChMFYWRtaW4xEzARBgNVBAsTCkV1Y2FseXB0dXMxGzAZBgNVBAMTEnd3dy5ldWNhbHlwdHVzLmNvbTAgFw0xMTExMTUxMDQ3MTZaGA8yMTExMTExNTEwNDcxNlowdDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1TYW50YSBCYXJiYXJhMQ4wDAYDVQQKEwVhZG1pbjETMBEGA1UECxMKRXVjYWx5cHR1czEbMBkGA1UEAxMSd3d3LmV1Y2FseXB0dXMuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwLlys8586hCjTJKyaFODcbCNhn/vhheNRghPk7zqJyIv8Vrt8QzIWYm1wCt91ZQf5X0qJkbK56a2s/8MaHOTYcq9ExhRn1ejHCTZ6KL4SkKDYq9AVrqGltkk5BOikGtfHdwj58k6F19Ky8h4m1WkG1GUF6ZDKoKt4WqqtDc35Qu5FZZ+nl4oEknjO4uZm0VzIMDTfM86vjEBh8wBpWVvf7NqA/V2RRZVufOWaNHTMtgvHk5TgAVPTVZ1zmsVSqVXozhNp0Yaycq1/DIfSf7NkuYGAZ6JzgHGcO0hgUvI1aE2tdgjJwbtp988lvWgr4Afb59CwMCojNPV+hVUc9jaHwIDAQABoxMwETAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDQUAA4IBAQBd273RefOVkJB41it8Y+eth3Z9VaLW02sPtycrOqhosp2J0ESubg7wlrrzU3ZtH+2jOBQkN3Nq0WD/+Krsg0wYSLP9FMGYuWUItQFswPBDf07eb8ES34//EAmEsustjkahOQI73heDl0vbR7VQDbGLAolnRAMyt8ItDY3Jj12VILCklN2ajrgXWG1pA3ikmxrQpQzzP3pn/Ci2PDUdcZ289J29b7yPTkidEoohNVn5rsy3zT0CB1oy40ypaoKM4vomC/9oT2LW0qzJBgzmlCofIHzANukI0SjCj6DlGJ/MuZ/TxBJsSHIVs5jGIpMwjUnYvtKToaV4bIo9siWg5oyw</o:BinarySecurityToken>
    			<Signature Id="_1" 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#hmac-sha1"/>
    					<Reference URI="#_3">
    						<Transforms>
    							<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    						</Transforms>
    						<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    						<DigestValue>xp7Ihtj7B727bbTQKpVFy2/hs2c=</DigestValue>
    					</Reference>
    					<Reference URI="#_4">
    						<Transforms>
    							<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    						</Transforms>
    						<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    						<DigestValue>sQ/b1JcfAvmJPZmawXPahtElJEs=</DigestValue>
    					</Reference>
    					<Reference URI="#_5">
    						<Transforms>
    							<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    						</Transforms>
    						<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    						<DigestValue>7ActATwdvrfelJL4rPl8D47jQTU=</DigestValue>
    					</Reference>
    					<Reference URI="#_6">
    						<Transforms>
    							<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    						</Transforms>
    						<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    						<DigestValue>CuNmjfm/U6y2+ZScFHyVRRpkyKQ=</DigestValue>
    					</Reference>
    					<Reference URI="#_7">
    						<Transforms>
    							<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    						</Transforms>
    						<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    						<DigestValue>9htZRTpGGVzFHPtO9FRJwEYEkTU=</DigestValue>
    					</Reference>
    					<Reference URI="#uuid-5c2b659b-cb39-49e7-8e89-d91aa7f7cc22-2">
    						<Transforms>
    							<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    						</Transforms>
    						<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    						<DigestValue>xLVB9BZttGowqAK/S+Esjl3SFvQ=</DigestValue>
    					</Reference>
    				</SignedInfo>
    				<SignatureValue>5RPZJJtPYkBPJnvA7aAlAHTMTBQ=</SignatureValue>
    				<KeyInfo>
    					<o:SecurityTokenReference>
    						<o:Reference URI="#_0"/>
    					</o:SecurityTokenReference>
    				</KeyInfo>
    			</Signature>
    			<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>NOntMlY7YpwgbQQS+vQrIAPQTME=</DigestValue>
    					</Reference>
    				</SignedInfo>
    				<SignatureValue>bYhpTEG3QtexmxmMRJnsi7gVEOFZpoAGLcAveSsplUEcrAVTZurGMDPhnZGw8Y3HCaNFqGDCyIZN4a2bYbGjFxrEpiZ1wQvl5SQe/WQJyAC5orRDTarQvL45oEhaXbfdolJKsCaupPMc7dD1C8AjPqnfvDYwQnbr2KNAf3n7/4j2v4RpmHHAfQ7e2M9BU2FXJAZKF/KiD6qme8pLSgRPTbKYe+x60wzwcvdCySjT4wlMDNJ5XChZ8Od7caMbX0QzJwM/LCqhQkUMNlZU5l0u948YEtTCH6JAwwHP9xXtUnbrUIlkpACRjavU3UokyGS1RJyQ4XVTQV4vyut4E+9trQ==</SignatureValue>
    				<KeyInfo>
    					<o:SecurityTokenReference>
    						<o:Reference URI="#uuid-9aae4e7c-5a25-4595-9ccc-d96758769583-1"/>
    					</o:SecurityTokenReference>
    				</KeyInfo>
    			</Signature>
    		</o:Security>
    	</s:Header>
    	<s:Body u:Id="_3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    		<DescribeInstances xmlns="http://abc.com/wsdl/esc/2011-06-16/">
    			<vmName>DDB03</vmName>
    		</DescribeInstances>
    	</s:Body>
    </s:Envelope>
    
    

    the soap request based on app.config :
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    	<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-db9ed307-f2e2-4bae-bac5-fc7f937df203-1">
    				<u:Created>2011-11-26T01:29:12.073Z</u:Created>
    				<u:Expires>2011-11-26T01:34:12.073Z</u:Expires>
    			</u:Timestamp>
    			<o:BinarySecurityToken u:Id="uuid-3cfba932-eb1b-4946-a2bb-df63f471d760-2" 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">MIIDfTCCAmWgAwIBAgIGATOm1oQ+MA0GCSqGSIb3DQEBDQUAMHQxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNU2FudGEgQmFyYmFyYTEOMAwGA1UEChMFYWRtaW4xEzARBgNVBAsTCkV1Y2FseXB0dXMxGzAZBgNVBAMTEnd3dy5ldWNhbHlwdHVzLmNvbTAgFw0xMTExMTUxMDQ3MTZaGA8yMTExMTExNTEwNDcxNlowdDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1TYW50YSBCYXJiYXJhMQ4wDAYDVQQKEwVhZG1pbjETMBEGA1UECxMKRXVjYWx5cHR1czEbMBkGA1UEAxMSd3d3LmV1Y2FseXB0dXMuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwLlys8586hCjTJKyaFODcbCNhn/vhheNRghPk7zqJyIv8Vrt8QzIWYm1wCt91ZQf5X0qJkbK56a2s/8MaHOTYcq9ExhRn1ejHCTZ6KL4SkKDYq9AVrqGltkk5BOikGtfHdwj58k6F19Ky8h4m1WkG1GUF6ZDKoKt4WqqtDc35Qu5FZZ+nl4oEknjO4uZm0VzIMDTfM86vjEBh8wBpWVvf7NqA/V2RRZVufOWaNHTMtgvHk5TgAVPTVZ1zmsVSqVXozhNp0Yaycq1/DIfSf7NkuYGAZ6JzgHGcO0hgUvI1aE2tdgjJwbtp988lvWgr4Afb59CwMCojNPV+hVUc9jaHwIDAQABoxMwETAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDQUAA4IBAQBd273RefOVkJB41it8Y+eth3Z9VaLW02sPtycrOqhosp2J0ESubg7wlrrzU3ZtH+2jOBQkN3Nq0WD/+Krsg0wYSLP9FMGYuWUItQFswPBDf07eb8ES34//EAmEsustjkahOQI73heDl0vbR7VQDbGLAolnRAMyt8ItDY3Jj12VILCklN2ajrgXWG1pA3ikmxrQpQzzP3pn/Ci2PDUdcZ289J29b7yPTkidEoohNVn5rsy3zT0CB1oy40ypaoKM4vomC/9oT2LW0qzJBgzmlCofIHzANukI0SjCj6DlGJ/MuZ/TxBJsSHIVs5jGIpMwjUnYvtKToaV4bIo9siWg5oyw</o:BinarySecurityToken>
    			<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>AKxOzDDRIYTY5aKo1F0FFWXPH5k=</DigestValue>
    					</Reference>
    					<Reference URI="#uuid-db9ed307-f2e2-4bae-bac5-fc7f937df203-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>Q6Ab5vSEFmFmsbGAqC+OulvTFnA=</DigestValue>
    					</Reference>
    				</SignedInfo>
    				<SignatureValue>eGEnh9Ejys0rbuhmxFUW1AXjnQA+awT8Wp+tpuw29ewZH4RYLO6G5rq2pG9GVnVeJ3icqaQ5IIqjPr1anPrIpThKEcNgXynHV0o8U7b07FKA2xev/yEqC0QdhMDsO6AzMxMbWsicKu8TSOtpkHaTHflc/be8RwdSpSO9CPp65jW8SPWYQP4D9/UwDuyA8suqujz/n44X3sT2qoWUdt7B33s85KSn/Rq+1gAM5r7s6EfDe6MdlfNUNqIsHrSyMkAq/pM9vUV7eCOcO+XySUj/kgeh2csN1/2ZDDnDsIIy4RVBu4rBDoTkWJfhUCvFaG64Eg6H68pzuciYBYhgclvOIQ==</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-3cfba932-eb1b-4946-a2bb-df63f471d760-2"/>
    					</o:SecurityTokenReference>
    				</KeyInfo>
    			</Signature>
    		</o:Security>
    	</s:Header>
    	<s:Body u:Id="_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    		<DescribeInstances xmlns="http://abc.com/wsdl/esc/2011-06-16/">
    			<instancesSet/>
    		</DescribeInstances>
    	</s:Body>
    </s:Envelope>
    
    

    I want the soap request based on program same with app.config made,what should i do?
    my best regards!thanks!





    • 已编辑 Tony TJ 2011年12月1日 0:45
    2011年11月26日 1:53

全部回复

  • anyone have ideas?
    2011年11月28日 0:18
  •  

    See the above listed code, the custom binding was not the same as the one used app.config. There are some differences between them, mainly indicate the MessageSecurityVersion property of security is different, and MessageVersion property of TextMessageEncoding is also different.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
    2011年11月29日 6:00
    版主
  •  

    Peter,thank you very much for your reply!

     

    I have changed my code like this:

     


    messageSecurity.MessageSecurityVersion = WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
    tmee.MessageVersion = MessageVersion.Soap11;

    it throw an exception like this:
    System.InvalidOperationException: 使用不兼容的安全版本配置协定(“PortTy
    pe”、“http://abc.com/wsdl/2011-06-16/”)的绑定(“CustomBind
    ing”、“http://tempuri.org/”),该版本不支持对 EncryptedKeys 的未附加引用。使用
    “WSSecurity11”或更高版本作为绑定的安全版本。

    There were some Chinese characters in the output,it means "Using an incompatible version of the configuration of contract,this version does not support the reference to the EncryptedKeys,Use "WSSecurity11" or later version as a binding security"

    what can i do?


     


    • 已编辑 Tony TJ 2011年12月1日 1:35
    2011年12月1日 1:35
  •  

    the code was looked like the same with app.config,but the error report like this,why?

    The binding ('{0}','{1}') for contract ('{2}','{3}') has been configured with an incompatible security version that does not support unattached references to EncryptedKeys. Use '{4}' or higher as the security version for the binding.

     

    messageSecurity.MessageSecurityVersion = WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
    tmee.MessageVersion = MessageVersion.Soap11;

    2011年12月6日 0:41