How to add security header to a SOAP message?











up vote
7
down vote

favorite
5












I'm trying to consume a WebService written in Java by our provider from our C# App. When it's time to communicate, I get this:




WSDoAllReceiver: Incoming message does not contain required Security header




Since yesterday I'm trying to find out how to add security header to a SOAP message.



Yes, I read this ( Clueless about how to create SOAP <wsse:Security> header ) but it did not work.



I looked around and this seems to be a rather asked question. I wonder if I can get some help here, some pointers, some code, to get me started.










share|improve this question




























    up vote
    7
    down vote

    favorite
    5












    I'm trying to consume a WebService written in Java by our provider from our C# App. When it's time to communicate, I get this:




    WSDoAllReceiver: Incoming message does not contain required Security header




    Since yesterday I'm trying to find out how to add security header to a SOAP message.



    Yes, I read this ( Clueless about how to create SOAP <wsse:Security> header ) but it did not work.



    I looked around and this seems to be a rather asked question. I wonder if I can get some help here, some pointers, some code, to get me started.










    share|improve this question


























      up vote
      7
      down vote

      favorite
      5









      up vote
      7
      down vote

      favorite
      5






      5





      I'm trying to consume a WebService written in Java by our provider from our C# App. When it's time to communicate, I get this:




      WSDoAllReceiver: Incoming message does not contain required Security header




      Since yesterday I'm trying to find out how to add security header to a SOAP message.



      Yes, I read this ( Clueless about how to create SOAP <wsse:Security> header ) but it did not work.



      I looked around and this seems to be a rather asked question. I wonder if I can get some help here, some pointers, some code, to get me started.










      share|improve this question















      I'm trying to consume a WebService written in Java by our provider from our C# App. When it's time to communicate, I get this:




      WSDoAllReceiver: Incoming message does not contain required Security header




      Since yesterday I'm trying to find out how to add security header to a SOAP message.



      Yes, I read this ( Clueless about how to create SOAP <wsse:Security> header ) but it did not work.



      I looked around and this seems to be a rather asked question. I wonder if I can get some help here, some pointers, some code, to get me started.







      c# web-services security






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 23 '17 at 11:46









      Community

      11




      11










      asked Apr 29 '11 at 14:43









      Adrian Carneiro

      43.6k1272114




      43.6k1272114
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          14
          down vote



          accepted










          I actually managed to achieve that by using WSE. The funny thing is that the provider's Web Services would not work with WSE 3.0, but they did with WSE 2.0. Here are the steps




          • Get WSE 2.0

          • Add the Web Reference to the project

          • In the Web Reference proxy implementation:


          Replace



          public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol


          by



          public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol



          • Before calling the Web Service:


          Set the authentication info



          UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
          yourProxy.RequestSoapContext.Security.Tokens.Add(token);


          And that's it! FYI, the provider is a Blackboard instance.






          share|improve this answer























          • So isn't it possible to consume a Blackboard web services using WCF?
            – Anthony Serdyukov
            Nov 22 '11 at 5:01










          • I never tried by WCF...
            – Adrian Carneiro
            Nov 22 '11 at 18:38










          • @AdrianCarneiro - Sooper awesome !
            – GuruC
            Nov 26 '12 at 6:56






          • 1




            Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
            – n00b
            Jun 9 '14 at 19:38






          • 2




            WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
            – Mark Dornian
            Jan 21 at 22:12


















          up vote
          0
          down vote













          Try this. No need to webreference and Web.Services2 implementation.



                      var client = "Your Service Client"; 
          using (var scope = new OperationContextScope(client.InnerChannel))
          {
          System.Xml.XmlDocument document = new XmlDocument();
          XmlElement element = document.CreateElement("wsse", "UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

          XmlElement newChild = null;
          newChild = document.CreateElement("wsse", "Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
          newChild.InnerText = "finance";
          element.AppendChild(newChild);

          newChild = document.CreateElement("wsse", "CorporationCode", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
          newChild.InnerText = "387";
          element.AppendChild(newChild);

          MessageHeader messageHeader = MessageHeader.CreateHeader("UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", element, false);

          OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

          var result = client.GetCorporations(new CorporationType { pageNo = 1 });
          }





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5833539%2fhow-to-add-security-header-to-a-soap-message%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            14
            down vote



            accepted










            I actually managed to achieve that by using WSE. The funny thing is that the provider's Web Services would not work with WSE 3.0, but they did with WSE 2.0. Here are the steps




            • Get WSE 2.0

            • Add the Web Reference to the project

            • In the Web Reference proxy implementation:


            Replace



            public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol


            by



            public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol



            • Before calling the Web Service:


            Set the authentication info



            UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
            yourProxy.RequestSoapContext.Security.Tokens.Add(token);


            And that's it! FYI, the provider is a Blackboard instance.






            share|improve this answer























            • So isn't it possible to consume a Blackboard web services using WCF?
              – Anthony Serdyukov
              Nov 22 '11 at 5:01










            • I never tried by WCF...
              – Adrian Carneiro
              Nov 22 '11 at 18:38










            • @AdrianCarneiro - Sooper awesome !
              – GuruC
              Nov 26 '12 at 6:56






            • 1




              Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
              – n00b
              Jun 9 '14 at 19:38






            • 2




              WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
              – Mark Dornian
              Jan 21 at 22:12















            up vote
            14
            down vote



            accepted










            I actually managed to achieve that by using WSE. The funny thing is that the provider's Web Services would not work with WSE 3.0, but they did with WSE 2.0. Here are the steps




            • Get WSE 2.0

            • Add the Web Reference to the project

            • In the Web Reference proxy implementation:


            Replace



            public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol


            by



            public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol



            • Before calling the Web Service:


            Set the authentication info



            UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
            yourProxy.RequestSoapContext.Security.Tokens.Add(token);


            And that's it! FYI, the provider is a Blackboard instance.






            share|improve this answer























            • So isn't it possible to consume a Blackboard web services using WCF?
              – Anthony Serdyukov
              Nov 22 '11 at 5:01










            • I never tried by WCF...
              – Adrian Carneiro
              Nov 22 '11 at 18:38










            • @AdrianCarneiro - Sooper awesome !
              – GuruC
              Nov 26 '12 at 6:56






            • 1




              Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
              – n00b
              Jun 9 '14 at 19:38






            • 2




              WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
              – Mark Dornian
              Jan 21 at 22:12













            up vote
            14
            down vote



            accepted







            up vote
            14
            down vote



            accepted






            I actually managed to achieve that by using WSE. The funny thing is that the provider's Web Services would not work with WSE 3.0, but they did with WSE 2.0. Here are the steps




            • Get WSE 2.0

            • Add the Web Reference to the project

            • In the Web Reference proxy implementation:


            Replace



            public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol


            by



            public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol



            • Before calling the Web Service:


            Set the authentication info



            UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
            yourProxy.RequestSoapContext.Security.Tokens.Add(token);


            And that's it! FYI, the provider is a Blackboard instance.






            share|improve this answer














            I actually managed to achieve that by using WSE. The funny thing is that the provider's Web Services would not work with WSE 3.0, but they did with WSE 2.0. Here are the steps




            • Get WSE 2.0

            • Add the Web Reference to the project

            • In the Web Reference proxy implementation:


            Replace



            public partial class UserWS : System.Web.Services.Protocols.SoapHttpClientProtocol


            by



            public partial class UserWS : Microsoft.Web.Services2.WebServicesClientProtocol



            • Before calling the Web Service:


            Set the authentication info



            UsernameToken token = new UsernameToken("user", "pwd", PasswordOption.SendPlainText);
            yourProxy.RequestSoapContext.Security.Tokens.Add(token);


            And that's it! FYI, the provider is a Blackboard instance.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 5 '11 at 12:24

























            answered May 4 '11 at 17:25









            Adrian Carneiro

            43.6k1272114




            43.6k1272114












            • So isn't it possible to consume a Blackboard web services using WCF?
              – Anthony Serdyukov
              Nov 22 '11 at 5:01










            • I never tried by WCF...
              – Adrian Carneiro
              Nov 22 '11 at 18:38










            • @AdrianCarneiro - Sooper awesome !
              – GuruC
              Nov 26 '12 at 6:56






            • 1




              Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
              – n00b
              Jun 9 '14 at 19:38






            • 2




              WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
              – Mark Dornian
              Jan 21 at 22:12


















            • So isn't it possible to consume a Blackboard web services using WCF?
              – Anthony Serdyukov
              Nov 22 '11 at 5:01










            • I never tried by WCF...
              – Adrian Carneiro
              Nov 22 '11 at 18:38










            • @AdrianCarneiro - Sooper awesome !
              – GuruC
              Nov 26 '12 at 6:56






            • 1




              Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
              – n00b
              Jun 9 '14 at 19:38






            • 2




              WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
              – Mark Dornian
              Jan 21 at 22:12
















            So isn't it possible to consume a Blackboard web services using WCF?
            – Anthony Serdyukov
            Nov 22 '11 at 5:01




            So isn't it possible to consume a Blackboard web services using WCF?
            – Anthony Serdyukov
            Nov 22 '11 at 5:01












            I never tried by WCF...
            – Adrian Carneiro
            Nov 22 '11 at 18:38




            I never tried by WCF...
            – Adrian Carneiro
            Nov 22 '11 at 18:38












            @AdrianCarneiro - Sooper awesome !
            – GuruC
            Nov 26 '12 at 6:56




            @AdrianCarneiro - Sooper awesome !
            – GuruC
            Nov 26 '12 at 6:56




            1




            1




            Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
            – n00b
            Jun 9 '14 at 19:38




            Everytime somebody updates the web regference, the reference gets wiped out (I need to wet it to microsoft.web.services2 again). is there anyway to stop that from happening or no?
            – n00b
            Jun 9 '14 at 19:38




            2




            2




            WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
            – Mark Dornian
            Jan 21 at 22:12




            WSE 2.0 can be added to your project via Nuget. nuget.org/packages/Microsoft.Web.Services2
            – Mark Dornian
            Jan 21 at 22:12












            up vote
            0
            down vote













            Try this. No need to webreference and Web.Services2 implementation.



                        var client = "Your Service Client"; 
            using (var scope = new OperationContextScope(client.InnerChannel))
            {
            System.Xml.XmlDocument document = new XmlDocument();
            XmlElement element = document.CreateElement("wsse", "UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

            XmlElement newChild = null;
            newChild = document.CreateElement("wsse", "Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            newChild.InnerText = "finance";
            element.AppendChild(newChild);

            newChild = document.CreateElement("wsse", "CorporationCode", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            newChild.InnerText = "387";
            element.AppendChild(newChild);

            MessageHeader messageHeader = MessageHeader.CreateHeader("UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", element, false);

            OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

            var result = client.GetCorporations(new CorporationType { pageNo = 1 });
            }





            share|improve this answer

























              up vote
              0
              down vote













              Try this. No need to webreference and Web.Services2 implementation.



                          var client = "Your Service Client"; 
              using (var scope = new OperationContextScope(client.InnerChannel))
              {
              System.Xml.XmlDocument document = new XmlDocument();
              XmlElement element = document.CreateElement("wsse", "UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

              XmlElement newChild = null;
              newChild = document.CreateElement("wsse", "Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
              newChild.InnerText = "finance";
              element.AppendChild(newChild);

              newChild = document.CreateElement("wsse", "CorporationCode", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
              newChild.InnerText = "387";
              element.AppendChild(newChild);

              MessageHeader messageHeader = MessageHeader.CreateHeader("UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", element, false);

              OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

              var result = client.GetCorporations(new CorporationType { pageNo = 1 });
              }





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Try this. No need to webreference and Web.Services2 implementation.



                            var client = "Your Service Client"; 
                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                System.Xml.XmlDocument document = new XmlDocument();
                XmlElement element = document.CreateElement("wsse", "UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

                XmlElement newChild = null;
                newChild = document.CreateElement("wsse", "Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                newChild.InnerText = "finance";
                element.AppendChild(newChild);

                newChild = document.CreateElement("wsse", "CorporationCode", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                newChild.InnerText = "387";
                element.AppendChild(newChild);

                MessageHeader messageHeader = MessageHeader.CreateHeader("UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", element, false);

                OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

                var result = client.GetCorporations(new CorporationType { pageNo = 1 });
                }





                share|improve this answer












                Try this. No need to webreference and Web.Services2 implementation.



                            var client = "Your Service Client"; 
                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                System.Xml.XmlDocument document = new XmlDocument();
                XmlElement element = document.CreateElement("wsse", "UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

                XmlElement newChild = null;
                newChild = document.CreateElement("wsse", "Username", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                newChild.InnerText = "finance";
                element.AppendChild(newChild);

                newChild = document.CreateElement("wsse", "CorporationCode", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                newChild.InnerText = "387";
                element.AppendChild(newChild);

                MessageHeader messageHeader = MessageHeader.CreateHeader("UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", element, false);

                OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader);

                var result = client.GetCorporations(new CorporationType { pageNo = 1 });
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 5:18









                B.Tekkan

                20125




                20125






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5833539%2fhow-to-add-security-header-to-a-soap-message%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Guess what letter conforming each word

                    Port of Spain

                    Run scheduled task as local user group (not BUILTIN)