question

MarkusFreitag-0088 avatar image
0 Votes"
MarkusFreitag-0088 asked MarkusFreitag-0088 commented

WCF POST request, GET request, test app server and client as desktop application

Hello,
public class FoodAnswer
{
public bool Result { get; set; }
public string ErrorCode { get; set; }
public string ErrorMessage { get; set; }
}

  public class FoodOrder
        {
            public bool Payed { get; set; }
            public string OrderID{ get; set; }
            public string Price{ get; set; }
        }


When I send a post request, how do I do it?

I need a HTTP server for testing. How can I create a test server for WPF desktop application?

I need it to call as POST? Can somebody give me a good sample? Step by step instruction.
Similar like this.
data-contract-and-known-type-in-wcf

http://localhost:8085/
http://localhost:8085/GetStudent?
http://localhost:8085/ Get or Post?




Here I can call a function, but I need a POST request.
How I can make a GET request, then I must see it on the browser my Json object, right?

Thanks for tips in advance. I want to use the Microsoft library, not a third party.

dotnet-csharpwindows-wcf
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am confused. I thought you were developing a WPF solution that needed to be doing duplex in a client/service solution with the service not being hosted on a Web server. I mentioned to you that you could use a selfhosting WCF service over TCP using NetTCP bindings. How is it that you are concerned about using HTTP verbs Get/Post used in Restful Web service, which can be done if the WCF service is an ASP.NET WCF Web service hosted on IIS that I know about.

https://www.codeproject.com/Articles/201901/CREATE-RESTful-WCF-Service-API-Using-POST-Step-By

If you want to get Json back from a WCF service or send it to the WCF service, then use Json.NET and Json serialize the object and just send it as a string parameter to/from the WCF client and service using Operational contracts and their methods(). Of course, you would have to Json deserialized the string back into a .NET object.

continued...

0 Votes 0 ·
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered MarkusFreitag-0088 commented

@MarkusFreitag-0088

I have given you two links in this thread that clearly shows how to use a WCF service that's using WCF NETTCPBindings. You need to look at those two links the WCF client side code doesn't use a URI that doesn't look like the URI(s) you or showing and posting to me about in your reply. You will be using TCP not HTTP there is no Post verb in in TCP in calling the WCF service from the WCF client side code that will be implemented in the WPF program using TCP.

I don't understand that you don't know to take two Windows desktop programs the WPF project that is hosting and running WCF client side code that is going to consume the WCF service that is being hosted and ran by the other Windows desktop project the console program.

The two projects would be in the same Visual Stuido solution .snl file and can be run concurrently in debug mode with them both communicating with each other through WCF in Visual Studio debug mode. You can debug on both sides of them running concurrently.

You should get the Web, HTTP, POST and IiS out of your mind you are using WCF over TCP and a console program hosting the WCF service over TCP not HTTP. I am sorry for any confusion.

A console program needs no Web server to host it. It is hosted by the O/S when it is deployed.

some other code to look at

https://developpaper.com/how-wcf-binds-nettcpbinding-to-host-console-application/

But the other two links I have provided clear show the code needed for the WCF service using TCP and the code you must implement in the WPF program, the WCF client, that is using TCP to communicate with the WCF service that is using TCP.

The other link is clearly showing how to implement nettcpbinding using duplex in a WCF service the will be implemented in a console program, and the WCF client side code needed in the WPF project. Or you go find a WCF project tutorial that needs to consume a WCF service using nettcpbindings the code is probably the same for a Windows form example that I have presented to you.

You should be able to figure it out. Actually, it is simple.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

          public class FoodOrder
          {
              public bool Payed { get; set; }
              public string OrderID{ get; set; }
              public string Price{ get; set; }
          }    
                
          POST
          http://localhost:8090/MyCalculatorOrder/OrderID=35244**
          ErrorMessage not exist
          Result = false
          ErrorCode=-1002
                
          public class FoodAnswer
          {
             public bool Result { get; set; }
             public string ErrorCode { get; set; }
             public string ErrorMessage { get; set; }
          }

As I said, I have a desktop app and have to request data from the customer via HTTP web. Since I don't have a server, I have to simulate it. I look at the example.

What is the difference between REST and HttpClient?

I will check this.
https://developpaper.com/how-wcf-binds-nettcpbinding-to-host-console-application

0 Votes 0 ·

As I said, I have a desktop app and have to request data from the customer via HTTP web. Since I don't have a server, I have to simulate it. I look at the example.
What is the difference between REST and HttpClient?

Oh, none what I have discussed is appropriate here. You have made serval posts on several topics in the C# tag form talking about duplex, TCP and HTTP in regards to one overall solution you were trying to achieve I assumed. You are not trying to achieve this.

So it's back to this simulation and testing a HTTP Post in a Restful Web service from client program using HTTPClient()?

Have you contacted this 3rd party vendor Web service provider to see if they have a means to test its Web service from a client's preceptive?

Continued...

1 Vote 1 ·

As far as coming up with some test simulation on your own, you'll have to create a ASP.NET WebAPI, a restful API over HTTP, project that's using IIS Express and make a Post Action method that the WPF project can use to test against. The WebAPI's data exchange default is Json. All of this has to remain in the realm of two Visual Stuido projects being in the same Visual Stuido solution so they can be debugged together.

Yes, you can start the WebAPI in Visual Stuido, it is going to show the Browser where you can drop a URL in the address bar, it will execute the WebAPI action method and if the method is returning Json data, it will be displayed in the browser.

https://www.tutorialsteacher.com/webapi/what-is-web-api
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-5.0
https://www.redhat.com/en/topics/api/what-is-a-rest-api

1 Vote 1 ·

OK, Thanks for all. I will do it.

0 Votes 0 ·
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered MarkusFreitag-0088 edited

continuation from comment reply, becuase something is wrong it wont submit with no explanation as to why it won't submit.

Anyway, you don't need a data contract if the WCF client and service are sending string data to each other.

Do you not understand that you can host a WCF service in a console program or a Windows form program removing the form out of the project, a formless program, using WCF NETTCP aka TCP using localhost?

If both those projects are in the same Visual Stuido solution, then you can start the console program that's hosting the WCF service, start the WPF program that is hosting the WCF client-side framework, with both programs being in debug mode, set breakpoints use Quickwatch and the whole nine yards.

When you're done debugging and everything works, then take the console exe or Windows formless exe and put the program on a hosting computer and run the program. Your WPF program the WCF client can communicate with the WCF service program over TCP by using WCF NETTCP bindings established in the app.config(s)

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the response. Yes looks good, good instruction.

Unfortunately it doesn't work. Do you have any idea why? IIS is here.
102686-missing-1.jpg


102687-missing-2.jpg


Yes I understand that I can host a windows program. When that works, I go to the browser that I should get XML or Json data, right?

Browser is the same as GET
I need POST with feedback.



The same as GET
http://localhost:35798/OrderID=2214124
ior
http://localhost:35798/OrderID=2211224



The same as POST
http://localhost:35798/OrderID=2214124;serialNo=24214;ProductNo=e214214
ior
http://localhost:35798/OrderID=2214124;serialNo=24214;ProductNo=e214222





0 Votes 0 ·
missing-1.jpg (86.1 KiB)
missing-2.jpg (90.9 KiB)

No, you are not using IIS. You are using IIS Express, which is not IIS a Web server. IIS Express is a Visual Stuido Web development tool, and it in no way is IIS that is hosted by the Windows O/S. The example link was a show and tell that you could do get and post in using an ASP.NET WCF service. You stated in the past that the whole solution the WPF and the WCF service needs to be an all Windows desktop solution. So how is it that you're going off course here in the understanding that the WCF service must be hosted by a Windows desktop program like a console program, Windows form or a Windows formless program that is going to use TCP communications WCF NETTCP?

https://www.c-sharpcorner.com/UploadFile/dinlov/wcf-using-nettcpbinding/
https://dotnetfalcon.com/duplex-service-over-tcp-with-wcf/

I believe I have given you the two links before. I have also told you that you can make a custom class/object and use Json.NET convert the custom object to Json.

continue..

1 Vote 1 ·

Json data is string data, you don't need a custom class as a datacontract just use a simple data container class and send the data back and forth as primitive type string

1 Vote 1 ·
Show more comments

One other thing, there is no browser involved here. You can use debug Quickwatch and view the content of a variable or object, and if it's Json sting data, it can be shown in a Json format I believe.

1 Vote 1 ·

I am a bit confused. What do I need now, what do I not. I have to implement an interface via HTTPWeb Client from the customer.

He can't give me a server. Therefore I would like to create this myself and test the answers.


How can I achieve this?

Which sample I need?

POST message from client.
http://localhost:35798/OrderID=2214124;serialNo=24214;ProductNo=e214214
or
http://localhost:35798/OrderID=2214124;serialNo=24214;ProductNo=e214222

0 Votes 0 ·