Wednesday, April 12, 2017

Hi! I said No! No! No more computing for a while....shit....I'm back to computing (everything in security is computing Elsa grow up!, So, I have here something it looks like the bird shitting on the cables corrosive shit :) Ok why am I doing this again, because industrial systems might have several SCADA type, let's imagine that the energy grid has this CANopen network (control system for multiple microcontrollers ant their use in automation) and so the protocol is SoupSocket that actually "SoupSocket is libsoup's TCP socket type. While it is primarily intended for internal use, SoupSockets are exposed in the API in various places, and some of their methods (eg, soup_socket_get_remote_address()) may be useful to applications." but besides this link, take a look at the comment bellow

How to get SOAP Message From .svc file methood


  • kuttikrishnankodoth

    kuttikrishna...

    Member
    9 Points
    48 Posts

    How to get SOAP Message From .svc file methood

    Jul 20, 2011 08:51 AM|LINK
    Hai Team ,
    Iam trying to access the in coming Soap message HEADER from  the server side svc file methood , through Operation Contract  class but  iam not getting the  value , iam using
    MessageHeaders messageHeaders = OperationContext
    .Current.IncomingMessageHeaders;
    int headerIndex = messageHeaders.FindHeader("ClientID"""
    );
    XmlReader r = OperationContext
    .Current.IncomingMessageHeaders.GetReaderAtHeader(headerIndex).ReadSubtree();
    XElement data = XElement
    .Load(r);
    int id = (int
    )data;
    where the client id is added to the SOAP  Header Dynamically  like
    using (OperationContextScope scope = new OperationContextScope(obj.InnerChannel as IClientChannel
    ))
    {
    MessageHeader msgHeader = MessageHeader.CreateHeader("ClientID""""1098"true
    );
    OperationContext
    .Current.OutgoingMessageHeaders.Add(msgHeader);
    txtResult.Text = obj.AddTheValues(
    Convert.ToInt32(txtFirstNumber.Text), Convert
    .ToInt32(txtSecNumber.Text)).ToString();
    }
    but iam not getting the value
    please help


    Think #
  • Peter pi - MSFT

    Peter pi - M...

    Star
    12801 Points
    1763 Posts

    Re: How to get SOAP Message From .svc file methood

    Jul 22, 2011 02:36 AM|LINK
    Hi,

    At the client try using
    MessageHeader msgHeader = MessageHeader.CreateHeader("ClientID", "ns", "1098", false);
    Instead of
    MessageHeader msgHeader = MessageHeader.CreateHeader("ClientID", "ns", "1098", true);
    and at the server try using
     int headerIndex = messageHeaders.FindHeader("ClientID", "ns");
    Instead of
    int headerIndex = messageHeaders.FindHeader("ClientID", "");
    Please refer to the following code snippet.
    class Client
        {
            static void Main()
            {
                // Create a client
                CalculatorClient client = new CalculatorClient();
                String RequestAction = "http://test/Message_RequestAction";
                using (new OperationContextScope(client.InnerChannel))
                {
                    // Call the Sum service operation.
                    int[] values = { 1, 2, 3, 4, 5 };
    
                    MessageHeader msgHeader = MessageHeader.CreateHeader("ClientID", "ns", "1098", false); OperationContext.Current.OutgoingMessageHeaders.Add(msgHeader);                 Message request = Message.CreateMessage(OperationContext.Current.OutgoingMessageHeaders.MessageVersion, RequestAction, values);
                    Message reply = client.ComputeSum(request);
                    int response = reply.GetBody();
    
                    Console.WriteLine("Sum of numbers passed (1,2,3,4,5,1098) = {0}", response);             }
    
                //Closing the client gracefully closes the connection and cleans up resources
                client.Close();
    
                Console.WriteLine();
                Console.WriteLine("Press  to terminate client.");
                Console.ReadLine();
            }
        }

        // Define a service contract.
        [ServiceContract(Namespace="http://Microsoft.Samples.Untyped")]
        public interface ICalculator
        {
            [OperationContract(Action = CalculatorService.RequestAction, ReplyAction = CalculatorService.ReplyAction)]
            Message ComputeSum(Message request);
        }
    
       
        // Service class which implements the service contract.
        public class CalculatorService : ICalculator
        {
            // Perform a calculation.
            public const String ReplyAction = "http://test/Message_ReplyAction";
            public const String RequestAction = "http://test/Message_RequestAction";
    
            public Message ComputeSum(Message request)
            {
                //The body of the message contains a list of numbers which will be read as a int[] using GetBody
                int result = 0;
    
                int[] inputs = request.GetBody<int[]>();
                foreach (int i in inputs)
                {
                    result += i;
                }
    
      MessageHeaders messageHeaders = OperationContext.Current.IncomingMessageHeaders; int headerIndex = messageHeaders.GetHeader("ClientID", "ns"); result += headerIndex;             Message response = Message.CreateMessage(request.Version, ReplyAction, result);
                return response;
            }
        }
    And maily focus on the bold font, hope this helps you.
    Best regards,
    Peter
    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 
  • kuttikrishnankodoth

    kuttikrishna...

    Member
    9 Points
    48 Posts

    Re: How to get SOAP Message From .svc file methood

    Jul 22, 2011 05:10 AM|LINK
    hai peter ,
    here iam using a wcf exposed Methood some thing like
    public list GetEmployeedetails(int empid,out  string Result)
    {
    // logic goes here ..
    }
    in this case how come i get the   Message request inside the metood to get the items
    Thanks very much
    Think #
  • kuttikrishnankodoth

    kuttikrishna...

    Member
    9 Points
    48 Posts

    Re: How to get SOAP Message From .svc file methood

    Jul 23, 2011 04:39 AM|LINK
    i  DONE LIKE
     // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MyTestService" in code, svc and config file together.
        public class MyTestService : IMyTestService
        {
            public int AddTheNumbers(int intA, int intB)
            {
                int intResult;
                string str = OperationContext.Current.RequestContext.RequestMessage.ToString();
                MessageHeaders messageHeaders = OperationContext.Current.IncomingMessageHeaders;
                string headerIndex = messageHeaders.GetHeader("ClientID", "ns");
               // result += headerIndex;             
               // Message response = Message.CreateMessage(request.Version, ReplyAction, result);
                //return response;
                ServiceManager objSM=new ServiceManager();
                 intResult=objSM.AddThenumbers(intA, intB);
              
                 return intResult;
            }
        }
    
    
    IN CLIENT SIDE
      protected void btnSum_Click(object sender, EventArgs e)
            {
                ServiceReference1.MyTestServiceClient objProxy = new ServiceReference1.MyTestServiceClient();
              
               
    
                using (new OperationContextScope(objProxy.InnerChannel))
                {
                    MessageHeader msgHeader = MessageHeader.CreateHeader("ClientID", "ns", "1098", false);
                    OperationContext.Current.OutgoingMessageHeaders.Add(msgHeader);
                    txtResult.Text = objProxy.AddTheNumbers(Convert.ToInt32(txtFirstNumber.Text), Convert.ToInt32(txtSecondNumber.Text)).ToString();
                }
                
            }
    NOW ITS WORKING FINE https://forums.asp.net/t/1701908.aspx?How+to+get+SOAP+Message+From+svc+file+methood+

Man in the Rain