Convert Swagger JSON to WCF contracts - wcf

I have a list of service contracts created in swagger, and I am trying to create WCF contracts based on that. As I see, I can use https://editor.swagger.io to convert swagger json to asp.net core server. But I can't seem to find anything that will help me convert this json to WCF contracts.
I thought of using SwaggerWCF nuget package, but that seems to allow only the conversion of WCF contracts to Swagger JSON, not the other way around. Is there something I am missing on that nuget package?
Or maybe there is some other tool that I can use to create WCF templates from Swagger?

you have swagger.json, you want to convert this json to WCF contracts.
1. convert json to .net class with SwaggerNet
2. create new assembly with System.Reflection.Emit.AssemblyBuilder
https://github.com/justin0522/SwaggerNet

Related

ASP.NET Web Api and Data Contracts

I want to create a client for this public WEB API. I am new to this and I was going through this MSDN tutorial. I noticed that there are no Data Contracts defined and i cannot add service reference in my project. In the tutorial in some point it says create this class (Product) as data object that HttpClient will use.
How can i find/create this class when using the public API. In WCF i can add service reference and i will get client classes created from the service data contract. How is this done in Web Api?
As illustrated in the MSDN article, since there's no defined contract (unlike WCF) you're gonna need to create the appropriate Types first in order to be able to consume it using REST client.
However, there are some shortcuts you can use, see here:
Generate Contracts for REST objects
Also, you may find RestSharp easier to use than the official WebApi client.

Expose WCF service to asmx client and WCF client

We have a WCF service that has operations which receive a List of data contract objects as their parameter and return a List of different data contract objects eg.
List<CheckOutResponse> ProcessCheckOut(List<CheckOutRequest> obj);
This service is currently being consumed by a WCF client and it works great.
We now need to expose the same service to a legacy application built on .NET 1.1. I understand the binding changes that I need to make in the service's web.config, use the basicHttp binding and set the correct service behavior etc.
My problem is the data contracts. I believe that the .NET 1.1 clients use the XMLSerializer and this cannot work with data contracts.
I really don't want to change the data contracts to some other .NET 1.1 compatible complex types because we'd then need a load of regression testing with the existing WCF client.
Has anyone worked out a solution to this problem?
There should be no problem with the serialization. The .NET 1.1 client will simply see a structure that places the values into elements instead of attributes.

Can I use Json serialization in WCF service?

I am going develop a WPF windows based application. I want to work with Entity Framework Self Tracking Entities and WCF. I was wondering if using Json is possible/recommended? If yes, please assist me; is there any tutorial that can help?
You can use the DataContractJsonSerializer to serialize the messages. You will have to use a REST based service (WebHttpBinding) as SOAP mandates XML as the message payload.
You can tell WCF to use the DatcontractJsonSerializer on the service side by settings in the WebGet and WebInvoke attributes but on the client side you will have to manually use this serializer as REST doesn;t have a metadata standard and therefore you have to create the requests and manage responses in a more manual fashion
Here is a reasonable guide to using Json and REST support in WCF
However, what is your driver to using Json? WCF is much more geared to SOAP based interaction currently (although the WCF 4.5 WebApi is going to address that to quite a degree). As your client is WPF you don't seem to gain alot from using Json

How to tweak default JSON serializer in WCF REST

WCF REST service works great in a way that it will reply/accept JSON or XML depending on header.
I want to tweak built-in JSON serializer a little so it encodes/decodes Byte[] little different. More specifically, I want to use Base64 for that.
Is that any pointers/samples where I can set custom type serializer that will affect whole service?
The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx shows how to replace the default JSON serializer (DataContractJsonSerializer) with a custom one (in this case, JSON.NET).
I just succeeded swapping out the default DataContractJsonSerializer with JSON.NET serializer in my WCF REST services 4.0 using NETFx Json.NET MediaTypeFormatter . Also see JSON.NET Serializer for WCF REST Services for the solution to a problem I ran into to get this working.

In WCF, how do I convert a Datatable to a format that will output in JSON store format without classes

So here's the problem - I have a DataTable I want WCF (.NET 3.5) to send out in a JSON store format commonly used in ExtJS, etc - basically "Rows[{"Field1":value,"Field2":value},{...}]" but I cannot find the right structure to feed back to the Operation contract to send it out in this format.
So any ideas, or any further info needed.
Thanks, in advance!
AndyPC, unfortunately, you're out of luck.
If you're dealing with an object whose type is an IXmlSerializable, the WCF JSON serializer delegates to IXmlSerializable methods first, gets the serialized XML out of them, wraps the XML in a JSON string, and just passes that on. This is one of the major weaknesses of the WCF JSON model in .NET 3.5. I think the entity framework (WCF Data Services) technologies try to handle this more elegantly, but not sure. I'd recommend manually using the JSON serializer and crafting up a string or a manual serialization mechanism that does what you want...