How to register Model from a library for a route request  Topic is solved

Discussions relating to the REST API of Jiwa 7.

How to register Model from a library for a route request

Postby symimake » Sat Aug 06, 2022 7:02 pm

I created a class library for my mart application and consuming that library inside the custom plugin. I have a custom route which drop the orders from my custom application to Jiwa.

Code: Select all
#region CustomRoute
public class CustomRoute : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
{
    public void Configure(Plugin Plugin, ServiceStackHost AppHost, Container Container, Manager JiwaApplicationManager)
    {
        AppHost.RegisterService<CustomService>();
        AppHost.Routes.Add(typeof(MyMart.Models.Order), "/MyMart/Orders", "POST", "add custom application order.", "");
    }
}
#endregion

#region CustomService

public class CustomService : ServiceStack.Service
{
    [Authenticate]
    public string MyMartOrder(MyMart.Models.Order order)
    {
        return order.Id;
    }
}

#endregion


This MyMartMdels.Order is coming referenced from the class library. I dont want to repeat that class also in the plugin because its contain 20-25 properties in it. I want to re-use it but I am getting the


Code: Select all
{
    "ResponseStatus": {
        "ErrorCode": "NotImplementedException",
        "Message": "Unable to resolve service 'Order'",
        "StackTrace": "   at ServiceStack.Host.ServiceController.GetService(Type requestType)\r\n   at ServiceStack.Host.ServiceController.<ExecuteAsync>d__47.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()"
    }
}
symimake
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Thu Jul 28, 2022 3:38 pm

Re: How to register Model from a library for a route request

Postby Mike.Sheen » Sat Aug 06, 2022 7:09 pm

On the Assembly References tab of the plugin, add your class library - do this by clicking the button to the right of the Full Name column, on the last row:
Plugin_AssemblyReferences.png


This will load a file browser dialog to allow you to select the class library.

Once you have done this, you can use the types defined in the class library within your plugin code.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How to register Model from a library for a route request

Postby symimake » Sat Aug 06, 2022 7:14 pm

Thanks. Let me try that but I already added the class library in embedded references. Still I need to reference it in assembly references?
symimake
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Thu Jul 28, 2022 3:38 pm

Re: How to register Model from a library for a route request

Postby symimake » Sat Aug 06, 2022 7:18 pm

I added the reference in Assembly reference also but still getting same error
symimake
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Thu Jul 28, 2022 3:38 pm

Re: How to register Model from a library for a route request

Postby Mike.Sheen » Sat Aug 06, 2022 10:08 pm

symimake wrote:Thanks. Let me try that but I already added the class library in embedded references.


You should have mentioned that. Information like this is pretty important.

symimake wrote:Still I need to reference it in assembly references?


No, you do not to reference it on the Assembly references tab if you already added it to the Embedded References.

Export your plugin to XML and attach it here, I should be able to work out what the problem is from there and I won't have to be guessing what you are trying to communicate.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How to register Model from a library for a route request

Postby symimake » Sat Aug 06, 2022 10:46 pm

I attached the plugin and the dll
Attachments
MyMart.zip
plugin zip
(8.35 KiB) Downloaded 104 times
symimake
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Thu Jul 28, 2022 3:38 pm

Re: How to register Model from a library for a route request  Topic is solved

Postby Mike.Sheen » Sun Aug 07, 2022 3:20 pm

It's because you've not got a method in the service matching the Verb - you need to have a method named Any, Get, Post, Put, Delete , Patch or Head.

Change This:

Code: Select all
public void MyMartOrder(MyMart.Models.Orders order)


To this:

Code: Select all
public void Post(MyMart.Models.Orders order)


And it will then work.

This is behaviour / requirement is from the ServiceStack framework - you should consider spending some time following some of their examples.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How to register Model from a library for a route request

Postby symimake » Sun Aug 07, 2022 6:43 pm

Did you try the attached plugin?

I updated the method Name and now I got a hit on my route.I send the Order object using Postman but why in Jiwa all values becoming null.

I think it is happening because the request dto is defined in a class library and because of this the request becoming null.

How can I define a transient dependency injection type for the service?
symimake
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Thu Jul 28, 2022 3:38 pm

Re: How to register Model from a library for a route request

Postby Mike.Sheen » Mon Aug 08, 2022 12:17 pm

symimake wrote:Did you try the attached plugin?


Yes, that's how I found the issue and could suggest the fix.

symimake wrote:I updated the method Name and now I got a hit on my route.I send the Order object using Postman but why in Jiwa all values becoming null.


That's a different problem to what you were reporting. What you reported was an exception :

Code: Select all
{
    "ResponseStatus": {
        "ErrorCode": "NotImplementedException",
        "Message": "Unable to resolve service 'Order'",
        "StackTrace": "   at ServiceStack.Host.ServiceController.GetService(Type requestType)\r\n   at ServiceStack.Host.ServiceController.<ExecuteAsync>d__47.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at ServiceStack.Host.RestHandler.<ProcessRequestAsync>d__14.MoveNext()"
    }
}


Which has now been identified and fixed in your plugin.

I'll now look at why "in Jiwa all values becoming null".

I'm assuming by that you mean the request DTO has null values - which I find highly unlikely, but that's all I can figure you mean from that statement. I'll post back my findings. Sharing what your request body and headers were would go a long way towards helping me to reproduce your issue.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: How to register Model from a library for a route request

Postby Mike.Sheen » Mon Aug 08, 2022 12:52 pm

Works for me.

This is my request body in Postman:
Post_Postman_Body.png


And the headers:
Post_Postman_Headers.png


And in Visual Studio, examining the request DTO using QuickWatch I see the expected values in the properties:
Post_Visual_Studio.png


Attached is your plugin with the previous change included - this is what I tested with - there is nothing special in there, it's just got the change I previously recommended.
Attachments
Plugin MyMartApi - 1.0.1.xml
(31.16 KiB) Downloaded 101 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Next

Return to REST API

Who is online

Users browsing this forum: No registered users and 2 guests