1

I'm having trouble understanding how to consume an existing ServiceStack based web service (https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/). I am using a standard vstudio .net 4.6 aspnet website c# form.

I tried adding the base service uri as a service reference to my existing project (Website > Add Service Reference > URI) but on building my solution I receive error: [Error: failed to generate code for the service reference. Cannot import wsdl:portType...].

I would like to think that I can interact with this service without manually building object definitions, so I must be missing a step.

Two questions:
1. Has anyone else worked with this particular service? Or can you suggest how to generate object definitions from this service? 2. Am I incorrectly assuming that generating the object definitions will give me full VStudio intellisense on my httpclient?

MTAdmin
  • 1,023
  • 3
  • 17
  • 36

1 Answers1

3

Since this is a ServiceStack Web Service you can use C# Add ServiceStack Reference to generate a Typed API in C# which you can use with ServiceStack's C# Service Clients.

The BaseUrl for this Service is:

https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/

So if you install ServiceStack VS from VS.NET Extension gallery:

enter image description here

You can create a Typed C# API by clicking on Add ServiceStack Reference on your project:

enter image description here

Then you can use the Typed DTOs with ServiceStack's generic Service Clients, e.g:

var baseUrl = "https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/";
var client = new JsonServiceClient(baseUrl);
var response = client.Post(new CreateCustomReport { ... });
mythz
  • 141,670
  • 29
  • 246
  • 390
  • OK thanks for the quick response. I add the SS Reference but the generated class has a series of errors beginning with "Type or namespace name 'DataContractAttribute' could not be found (are you missing...)", "'DataContract' could not be found ... etc. – MTAdmin Jul 13 '18 at 19:11
  • @MTAdmin That's [.NET `[DataContract]` Attribute](https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx?f=255&MSPPError=-2147217396), you need to [add a reference to System.Runtime.Serialization.dll](https://stackoverflow.com/a/7401828/85785) – mythz Jul 13 '18 at 19:13
  • OK, maybe I'm getting closer to the question I should be asking...VS (2015/2017) doesn't have a menu option to add an SS Reference in an existing aspnet site. I tried to work around that by adding a separate SS project to my existing solution. Having both projects in one solution causes VS to indicate errors with the DataContract in the generated class file. So - is there any way to add a SS Reference to an existing aspnet website? – MTAdmin Jul 13 '18 at 19:46
  • 1
    @MTAdmin My answer shows how to Add a ServiceStack Reference to an existing project. I don't know what your error you're getting but it sounds like a dependency conflict. You can add a reference without a UI by including [TransFirst.Transaction.Web/api/types/csharp](https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/types/csharp) source file in your project and manually adding a reference to [ServiceStack.Client](https://www.nuget.org/packages/ServiceStack.Client) NuGet package. – mythz Jul 13 '18 at 19:50
  • Adding the static types source file answers my question. I suppose this introduces the possibility of future source changes breaking my offline types but I can live with this for now. Thanks for your help! – MTAdmin Jul 13 '18 at 20:55
  • @MTAdmin The source file never changes unless you update the service reference or download the latest copy. If they only make [the recommended backwards-compatible versionable changes](https://stackoverflow.com/a/12413091/85785) the old DTO's and Service Requests will continue to work despite not using the latest DTOs. – mythz Jul 13 '18 at 21:00