Beispiel #1
0
 protected virtual void AddHeadersTo(Message message)
 {
     if (!_manualAddressing && _to != null)
     {
         _to.ApplyTo(message);
     }
 }
Beispiel #2
0
        internal static bool AddressReply(Message reply, ReplyToInfo info)
        {
            EndpointAddress destination = null;

            if (info.HasFaultTo && (reply.IsFault))
            {
                destination = info.FaultTo;
            }
            else if (info.HasReplyTo)
            {
                destination = info.ReplyTo;
            }
            else if (reply.Version.Addressing == AddressingVersion.WSAddressingAugust2004)
            {
                if (info.HasFrom)
                {
                    destination = info.From;
                }
                else
                {
                    destination = EndpointAddress.AnonymousAddress;
                }
            }

            if (destination != null)
            {
                destination.ApplyTo(reply);
                return(!destination.IsNone);
            }
            else
            {
                return(true);
            }
        }
        internal static bool AddressReply(Message reply, ReplyToInfo info)
        {
            EndpointAddress faultTo = null;

            if (info.HasFaultTo && reply.IsFault)
            {
                faultTo = info.FaultTo;
            }
            else if (info.HasReplyTo)
            {
                faultTo = info.ReplyTo;
            }
            else if (reply.Version.Addressing == AddressingVersion.WSAddressingAugust2004)
            {
                if (info.HasFrom)
                {
                    faultTo = info.From;
                }
                else
                {
                    faultTo = EndpointAddress.AnonymousAddress;
                }
            }
            if (faultTo != null)
            {
                faultTo.ApplyTo(reply);
                return(!faultTo.IsNone);
            }
            return(true);
        }
Beispiel #4
0
        Message IClientMessageFormatter.SerializeRequest(MessageVersion messageVersion, object[] parameters)
        {
            Message message = Message.CreateMessage(messageVersion, action);

            address.ApplyTo(message);
            UriBuilder builder = new UriBuilder(message.Headers.To);

            builder.Path           = builder.Path + "/" + this.operationName;
            builder.Query          = SerializeParameters(parameterInfos, parameters);
            message.Headers.To     = builder.Uri;
            message.Properties.Via = builder.Uri;

            return(message);
        }
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage methodCall = (IMethodCallMessage)msg;

            //得到操作名称
            object[] attributes = methodCall.MethodBase.GetCustomAttributes(typeof(OperationContractAttribute), true);
            OperationContractAttribute attribute = (OperationContractAttribute)attributes[0];
            string operationName = string.IsNullOrEmpty(attribute.Name) ? methodCall.MethodName : attribute.Name;

            //序列化请求消息
            Message requestMessage = this.MessageFormatters[operationName].SerializeRequest(this.MessageVersion, methodCall.InArgs);

            //添加必要的WS-Address报头
            EndpointAddress address = new EndpointAddress(this.Address);

            requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid());
            requestMessage.Headers.ReplyTo   = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");
            address.ApplyTo(requestMessage);

            //对请求消息进行编码,并将编码生成的字节发送通过HttpWebRequest向服务端发送
            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(this.Address);

            webRequest.Method      = "Post";
            webRequest.KeepAlive   = true;
            webRequest.ContentType = "application/soap+xml; charset=utf-8";
            ArraySegment <byte> bytes = this.MessageEncoderFactory.Encoder.WriteMessage(requestMessage, int.MaxValue, BufferManager.CreateBufferManager(long.MaxValue, int.MaxValue));

            webRequest.ContentLength = bytes.Array.Length;
            webRequest.GetRequestStream().Write(bytes.Array, 0, bytes.Array.Length);
            webRequest.GetRequestStream().Close();
            WebResponse webResponse = webRequest.GetResponse();

            //对HttpResponse进行解码生成回复消息.
            Message responseMessage = this.MessageEncoderFactory.Encoder.ReadMessage(webResponse.GetResponseStream(), int.MaxValue);

            //回复消息进行反列化生成相应的对象,并映射为方法调用的返回值或者ref/out参数
            object[] allArgs = (object[])Array.CreateInstance(typeof(object), methodCall.ArgCount);
            Array.Copy(methodCall.Args, allArgs, methodCall.ArgCount);
            object[] refOutParameters = new object[GetRefOutParameterCount(methodCall.MethodBase)];
            object   returnValue      = this.MessageFormatters[operationName].DeserializeReply(responseMessage, refOutParameters);

            MapRefOutParameter(methodCall.MethodBase, allArgs, refOutParameters);

            //通过ReturnMessage的形式将返回值和ref/out参数返回
            return(new ReturnMessage(returnValue, allArgs, allArgs.Length, methodCall.LogicalCallContext, methodCall));
        }
Beispiel #6
0
        public static void Snippet4()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };

            EndpointIdentity endpointIdentity = EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name);
            EndpointAddress  endpointAddress  = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), endpointIdentity, addressHeaders);
            // <Snippet4>
            Message msg = Message.CreateMessage(MessageVersion.Soap11, "urn:action");

            endpointAddress.ApplyTo(msg);
            // </Snippet4>
        }
Beispiel #7
0
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage msg)
        {
            IMethodCallMessage methodCall = (IMethodCallMessage)msg;

            //得到操作名称
            object[] attributes = methodCall.MethodBase.GetCustomAttributes(typeof(OperationContractAttribute), false);
            OperationContractAttribute attribute = attributes[0] as OperationContractAttribute;
            string operationName = string.IsNullOrEmpty(attribute.Name) ? methodCall.MethodName : attribute.Name;

            Message requestMessage = MessageFormatter[operationName].SerializeRequest(this.MessageVersion, methodCall.InArgs);

            EndpointAddress address = new EndpointAddress(this.Address);

            requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid());
            requestMessage.Headers.ReplyTo   = new EndpointAddress("http://www.w3.org/2005/08/addressing/anonymous");
            address.ApplyTo(requestMessage);

            HttpWebRequest web = (HttpWebRequest)HttpWebRequest.Create(Address);

            web.Method      = "Post";
            web.KeepAlive   = true;
            web.ContentType = "application/soap+xml; charset=utf-8";


            ArraySegment <byte> bytes = this.MessageEncoderFactory.Encoder.WriteMessage(requestMessage, int.MaxValue, BufferManager.CreateBufferManager(long.MaxValue, int.MaxValue));

            web.ContentLength = bytes.Array.Length;
            web.GetRequestStream().Write(bytes.Array, 0, bytes.Array.Length);
            web.GetRequestStream().Close();
            WebResponse response = (WebResponse)web.GetResponse();

            //回复消息进行反列化生成相应的对象,并映射为方法调用的返回值或者ref/out参数
            object[] allArgs = (object[])Array.CreateInstance(typeof(object), methodCall.ArgCount);
            Array.Copy(methodCall.Args, allArgs, methodCall.ArgCount);
            Message responseMessage = this.MessageEncoderFactory.Encoder.ReadMessage(response.GetResponseStream(), int.MaxValue);
            object  result          = this.MessageFormatter[operationName].DeserializeReply(responseMessage, new object[GetRefOutParamterCount(methodCall.MethodBase)]);

            MapRefOutParameter(methodCall.MethodBase, allArgs, new object[GetRefOutParamterCount(methodCall.MethodBase)]);
            return(new ReturnMessage(result, allArgs, allArgs.Length, methodCall.LogicalCallContext, methodCall));
        }
        internal static bool AddressReply(Message reply, ReplyToInfo info)
        {
            EndpointAddress destination = null;

            if (info.HasFaultTo && (reply.IsFault))
            {
                destination = info.FaultTo;
            }
            else if (info.HasReplyTo)
            {
                destination = info.ReplyTo;
            }

            if (destination != null)
            {
                destination.ApplyTo(reply);
                return(!destination.IsNone);
            }
            else
            {
                return(true);
            }
        }
Beispiel #9
0
        internal static bool AddressReply(Message reply, Microsoft.ServiceBus.Channels.RequestReplyCorrelator.ReplyToInfo info)
        {
            EndpointAddress faultTo = null;

            if (info.HasFaultTo && reply.IsFault)
            {
                faultTo = info.FaultTo;
            }
            else if (info.HasReplyTo)
            {
                faultTo = info.ReplyTo;
            }
            else if (reply.Version.Addressing == AddressingVersion.WSAddressingAugust2004)
            {
                faultTo = (!info.HasFrom ? EndpointAddress2.AnonymousAddress : info.From);
            }
            if (faultTo == null)
            {
                return(true);
            }
            faultTo.ApplyTo(reply);
            return(!faultTo.IsNone);
        }