none
IsOneWay not working RRS feed

  • Question

  • Hi, 

    I am trying to set up a fire and forget REST message that will just fire once from another REST message and let this carry on.

    To explain better what we have is a REST service that waits for orders to come in, once we receive and save the order we then send this order on to a distributor. I can get this to work when i haven't added the;

    [OperationContract(IsOneWay=true)]

    but when I add this in I get a status of Accepted which i would assume is correct but the actual code to transmit to the distributor isn't running. 

    this is the code in MY transmit order REST message.

        [ServiceContract]
        public interface IHubTransmitOrder
        {
            // change method to POST GET PUT dependant on what you need to do
            // change WebCall to what you need it to be
            // change actionWebCall to process web call {insert, get, update}
            [OperationContract(IsOneWay=true)]
            [WebInvoke(Method = "PUT",
                ResponseFormat = WebMessageFormat.Xml,
                RequestFormat = WebMessageFormat.Xml,
                BodyStyle = WebMessageBodyStyle.Bare,
                UriTemplate = "TransmitSalesOrder")]
            void TransmitOrder(TransmitOrderRequest request);
        }

    This is the code calling the above REST message;

     private void TransmitSalesOrder()
            {  
                // instanciate the request and response objects
                HttpWebRequest objHttpWebRequest;
                HttpWebResponse objHttpWebResponse = null;
                Stream objRequestStream = null;
                
                try
                {
                    //Stream objResponseStream = null;
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(string.Format("<transmitOrderRequest><salesOrderID>{0}</salesOrderID></transmitOrderRequest>", SalesOrder.DBSalesOrder.salesOrderID));
    
                  Broker brokerDetails = BrokerFactory.GetBrokerDetails(ServiceUtil.SYSTEM_ID_COT, ServiceUtil.PREFIX_COT);
                    TransactionFactory.Response(xml, ServiceUtil.SERVICE_NAME, SalesOrder.DBSalesOrder.clientOrderNumber);
                    // set the endpoint
                    objHttpWebRequest = (HttpWebRequest)WebRequest.Create(brokerDetails.endpoint);
                    // set the byte array and fill with the request
                    byte[] bytes;
                    bytes = Encoding.ASCII.GetBytes(xml.InnerXml);
                    // set the web request details
                    objHttpWebRequest.Method = "PUT";
                    objHttpWebRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(string.Format("{0}:{1}", brokerDetails.username, brokerDetails.password)));
                    objHttpWebRequest.ContentLength = bytes.Length;
                    objHttpWebRequest.ContentType = "application/xml; encoding='utf-8'";
                    // set the request stream
                    objRequestStream = objHttpWebRequest.GetRequestStream();
                    // send the request 
                    objRequestStream.Write(bytes, 0, bytes.Length);
                    // close the request stream
                    objRequestStream.Close();
                    // set the XML document
                    XmlDocument xmlDoc = new XmlDocument();
                    // get the response
                    objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
                    // check the request response status code
                    if (objHttpWebResponse.StatusCode != HttpStatusCode.OK)
                    {   // if not OK then mark as transmission error
                        //DataLayer.ChangeStatusSalesOrder(salesOrderID, BrokerUtil.ERROR_TRANSMITTED, "", "");
                        LoggerFactory.AddWarning(string.Format("Received status {0} for client order number {1}", objHttpWebResponse.StatusCode, SalesOrder.DBSalesOrder.clientOrderNumber));
                    }
                }
                catch (Exception ex)
                {
                    LoggerFactory.AddException(ex);
                }
                finally
                {   // close and clear out all the request and response streams
                    if (objRequestStream != null) objRequestStream.Close();
                    if (objRequestStream != null) objRequestStream.Close();
                    if (objHttpWebResponse != null) objHttpWebResponse.Close();
    
                    //Release objects
                    objRequestStream = null;
                    //objResponseStream = null;
                    objHttpWebResponse = null;
                    objHttpWebRequest = null;
                }
            }

    Hope someone can help on this. If you need any further information to get this working then let me know.

    Regards

    Aidan

     
    Friday, March 11, 2016 1:52 PM

Answers

  • Hi Aidan.b,

    >>which we use to get the actual REST Xml sent for auditing is there some reason this would fail when using IsOneWay?

    Yes, it will fail. It is because that when we use the IsOneWay, the OperationContext.Current.RequestContext.RequestMessage will be null, then we couldn’t use the ToStirng method on it.
    For the detailed information about this, please refer to:
    https://blogs.msdn.microsoft.com/drnick/2006/08/25/why-is-the-requestcontext-null/ .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 17, 2016 8:41 AM
    Moderator

All replies

  • Hi Aidan.b

    Use the IsOneWay property to indicate that an operation does not return a response message. I would suggest that you could log the some operation in your WCF rest service. and according to log files to check if it works for you.

    for more information about IsOneWay property, please refer to the following link

    https://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isoneway(v=vs.110).aspx

    Best regards.

    Monday, March 14, 2016 8:43 AM
  • Hi,

    I have put logging in now and i can find out that it is due to this.

    OperationContext.Current.RequestContext.RequestMessage.ToString();

    which we use to get the actual REST Xml sent for auditing is there some reason this would fail when using IsOneWay?

    Regards

    Aidan

    Monday, March 14, 2016 9:17 AM
  • Hi Aidan.b,

    >>which we use to get the actual REST Xml sent for auditing is there some reason this would fail when using IsOneWay?

    Yes, it will fail. It is because that when we use the IsOneWay, the OperationContext.Current.RequestContext.RequestMessage will be null, then we couldn’t use the ToStirng method on it.
    For the detailed information about this, please refer to:
    https://blogs.msdn.microsoft.com/drnick/2006/08/25/why-is-the-requestcontext-null/ .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 17, 2016 8:41 AM
    Moderator