Example #1
0
    public static void Test()
    {
        string          baseAddress = "http://" + Environment.MachineName + ":8000/Service";
        ServiceHost     host        = new ServiceHost(typeof(Service), new Uri(baseAddress));
        ServiceEndpoint endpoint    = host.AddServiceEndpoint(typeof(ITest), new WSHttpBinding(), "");

        host.Open();
        Console.WriteLine("Host opened");
        ChannelFactory <ITest> factory   = new ChannelFactory <ITest>(new WSHttpBinding(), new EndpointAddress(baseAddress));
        MyInspector            inspector = new MyInspector {
            NewHeaderValue = "Modified header value"
        };

        factory.Endpoint.Behaviors.Add(inspector);
        ITest proxy = factory.CreateChannel();

        proxy.Process(new MyMC {
            HeaderValue = "Original header value", BodyValue = "The body"
        });
        ((IClientChannel)proxy).Close();
        factory.Close();
        Console.Write("Press ENTER to close the host");
        Console.ReadLine();
        host.Close();
    }
Example #2
0
    public static void MessageBody_Elements_CustomerElement_Value_Matches()
    {
        MessageContractHelpers.IMessageContract clientProxy;
        MessageContractTypes.RequestBankingData requestData;
        MyInspector inspector = MessageContractHelpers.SetupMessageContractTests(out clientProxy, out requestData);

        clientProxy.MessageContractRequestReply(requestData);
        XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector);

        bool elementFound = false;

        while (reader.Read())
        {
            if (reader.LocalName.Equals(MessageContractConstants.customerElementName) && reader.NamespaceURI.Equals(MessageContractConstants.customerElementNamespace))
            {
                elementFound = true;
                reader.ReadStartElement();
                Assert.Equal(reader.Value, MessageContractConstants.customerElementValue);
                break;
            }
            else
            {
                // Continue checking remaining nodes.
            }
        }

        Assert.True(elementFound,
                    string.Format("Expected element not found. Looking For: {0} && {1}", MessageContractConstants.customerElementName, MessageContractConstants.customerElementNamespace));
    }
Example #3
0
    public static void MessageContract_IsWrapped_False()
    {
        MessageContractHelpers.IMessageContract clientProxy;
        MessageContractTypes.RequestBankingData requestData;
        MyInspector inspector = MessageContractHelpers.SetupMessageContractTests(out clientProxy, out requestData);

        clientProxy.MessageContractRequestReplyNotWrapped(requestData);
        XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector);

        Assert.False(reader.LocalName.Equals(MessageContractConstants.wrapperName),
                     "When IsWrapped set to false, the message body should not be wrapped with an extra element.");
    }
Example #4
0
    public static void MessageContract_IsWrapped_True()
    {
        MessageContractHelpers.IMessageContract clientProxy;
        MessageContractTypes.RequestBankingData requestData;
        MyInspector inspector = MessageContractHelpers.SetupMessageContractTests(out clientProxy, out requestData);

        clientProxy.MessageContractRequestReply(requestData);
        XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector);

        Assert.True(reader.LocalName.Equals(MessageContractConstants.wrapperName),
                    string.Format("reader.LocalName - Expected: {0}, Actual: {1}", MessageContractConstants.wrapperName, reader.LocalName));

        Assert.True(reader.NamespaceURI.Equals(MessageContractConstants.wrapperNamespace),
                    string.Format("reader.NamespaceURI - Expected: {0}, Actual: {1}", MessageContractConstants.wrapperNamespace, reader.NamespaceURI));
    }
Example #5
0
    public static void MessageHeader_MustUnderstand_False()
    {
        MessageContractHelpers.IMessageContract clientProxy;
        MessageContractTypes.RequestBankingData requestData;
        MyInspector inspector = MessageContractHelpers.SetupMessageContractTests(out clientProxy, out requestData);

        clientProxy.MessageContractRequestReplyWithMessageHeaderNotNecessaryUnderstood(requestData);
        MessageHeaders headers = MessageContractHelpers.GetHeaders(inspector);

        int index  = headers.FindHeader(MessageContractConstants.extraValuesName, MessageContractConstants.extraValuesNamespace);
        var header = headers[index];

        Assert.True(header != null, "There's no header in the message.");
        Assert.False(header.MustUnderstand, "Expected MustUnderstand to be false, but it was true.");
    }
Example #6
0
 public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 {
     foreach (var operation in endpoint.Contract.Operations)
     {
         string[] inputParamNames = operation.Messages[0].Body.Parts
                                    .OrderBy(mpd => mpd.Index)
                                    .Select(mpd => mpd.Name)
                                    .ToArray();
         string[] outputParamNames = null;
         if (operation.Messages.Count > 1)
         {
             outputParamNames = operation.Messages[1].Body.Parts
                                .OrderBy(mpd => mpd.Index)
                                .Select(mpd => mpd.Name)
                                .ToArray();
         }
         MyInspector inspector = new MyInspector(inputParamNames, outputParamNames);
         endpointDispatcher.DispatchRuntime.Operations[operation.Name].ParameterInspectors.Add(inspector);
     }
 }
Example #7
0
    public static void MessageBody_Elements_Ordered()
    {
        MessageContractHelpers.IMessageContract clientProxy;
        MessageContractTypes.RequestBankingData requestData;
        MyInspector inspector = MessageContractHelpers.SetupMessageContractTests(out clientProxy, out requestData);

        clientProxy.MessageContractRequestReply(requestData);
        XmlDictionaryReader reader = MessageContractHelpers.GetResponseBodyReader(inspector);

        string wrapperName = "ReplyBankingDataWrapper";

        Assert.True(reader.LocalName.Equals(wrapperName),
                    string.Format("Unexpected element order (1/5). Expected {0}, Actual: {1}", wrapperName, reader.LocalName));

        reader.Read();

        Assert.True(reader.LocalName.Equals(MessageContractConstants.dateElementName),
                    string.Format("Unexpected element order (2/5). Expected {0}, Actual: {1}", MessageContractConstants.dateElementName, reader.LocalName));

        reader.Read();           // Move to Value node
        reader.Read();           // Move to the end tag
        reader.ReadEndElement(); // Checks that the current content node is an end tag and advances the reader to the next node.

        Assert.True(reader.LocalName.Equals(MessageContractConstants.transactionElementName),
                    string.Format("Unexpected element order (3/5). Expected: {0}, Actual: {1}", MessageContractConstants.transactionElementName, reader.LocalName));

        reader.Read();           // Move to Value node
        reader.Read();           // Move to the end tag
        reader.ReadEndElement(); // Checks that the current content node is an end tag and advances the reader to the next node.

        Assert.True(reader.LocalName.Equals(MessageContractConstants.customerElementName),
                    string.Format("Unexpected element order (4/5). Expected: {0}, Actual: {1}", MessageContractConstants.customerElementName, reader.LocalName));


        reader.Read();           // Move to Value node
        reader.Read();           // Move to the end tag
        reader.ReadEndElement(); // Checks that the current content node is an end tag and advances the reader to the next node.

        Assert.True(reader.IsStartElement() == false && reader.LocalName.Equals(wrapperName),
                    string.Format("Unexpected element order (5/5). Expected: {0}, Actual: {1}", wrapperName, reader.LocalName));
    }