Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

{ "string001Value":"LITTELFUSE \/ 772291851034","string002Value":"772291851034","string003Value":"","string004Value":""... }

When sending a Json object the WCF service receives it without the backslash '', the string001Value property receives the value of "LITTELFUSE / 772291851034".

How can I receive this type of characters in the service so that the value is "LITTELFUSE / 772291851034"?

this is the WebInvoke Method:

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, 
           RequestFormat = WebMessageFormat.Json, 
           ResponseFormat = WebMessageFormat.Json, 
           UriTemplate = "warehouse_shipping_advice")]
_ResponseDetail WarehouseShippingAdvice(_WarehouseShipping newWarehouseShipping);
question from:https://stackoverflow.com/questions/65545474/unable-to-receive-character-in-post-wcf-request-net-c-sharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

According to your description, I did a test but did not find the problem, here is my demo:

 [ServiceContract]
    public interface IService1
    {
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "warehouse_shipping_advice")]
        void WarehouseShippingAdvice(_WarehouseShipping newWarehouseShipping);
    }
    [DataContract]
    public class _WarehouseShipping
    {
        [DataMember]
        public string string001Value { get; set; }
    }
    public class Service1 : IService1
    {
        public void WarehouseShippingAdvice(_WarehouseShipping newWarehouseShipping)
        {
            Console.WriteLine(newWarehouseShipping.string001Value);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            // Step 1: Create a URI to serve as the base address.
            Uri baseAddress = new Uri("http://localhost:8000/GettingStarted/");

            // Step 2: Create a ServiceHost instance.
            ServiceHost selfHost = new ServiceHost(typeof(Service1), baseAddress);

            try
            {
                // Step 3: Add a service endpoint.
                selfHost.AddServiceEndpoint(typeof(IService1), new WebHttpBinding(), "CalculatorService").Behaviors.Add(new WebHttpBehavior() { HelpEnabled=true});

                // Step 4: Enable metadata exchange.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Step 5: Start the service.
                selfHost.Open();
                Console.WriteLine("The service is ready.");

                // Close the ServiceHost to stop the service.
                Console.WriteLine("Press <Enter> to terminate the service.");
                Console.WriteLine();
                Console.ReadLine();
                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
    }

This is my service. I enabled the help document in the service.

enter image description here

According to the help document, we can request the service correctly.

enter image description here

UPDATE

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...