Questions about webapi

Aug 11, 2013 at 7:01 AM
Edited Aug 11, 2013 at 7:02 AM
Today I've downloaded the latest version of code and found the webapi.Seems very interesting! Just two questions.

1)I need access for other adress than 127.0.0.1, like LAN ip's. Where can I config that?

2)It is possible to host the web API in IIS?

Thanks!
Coordinator
Aug 11, 2013 at 2:11 PM
1) You don't need to change the configuration to make it work for LAN ip's. When the webapi is installed on your server, it is automatically configure to be accessible on your LAN ip even though it might look like it was configure for 127.0.0.1. Default configuration does not mean the webapi will only listen to connection of localhost, but also any ip-address configure for the server meaning that your LAN ips will be fine. I am also using it over the internet and it works fine. As you can see below, the only thing that specify 127.0.0.1 is the ESB endpoint itself which means it is assuming that the ESB is running on the same machine as the web api. As for the webapi itself, it just listen on any interface. So if you want your webapi to connect to a different ESB server that is not running on the webapi machine, then you can change the 127.0.0.1 aspect of it
<?xml version="1.0" encoding="utf-8" ?>
<services>
  <service id="PServiceBus.WebAPI" port="8087" secured="false" certthumbprint="" appid="" esbEndpoint="endpoint://127.0.0.1:8000" name="PServiceBus.WebAPI" messageBusType="PServiceBus.Gateway.ZeroMQ.ZeroMQMessageBus" dependon="PServiceBus.Redis Server"/>
 </services>
2) It is possible to host the Web API in IIS if you make some changes to the way it is setup, but why would you want IIS if it can run properly in self-host mode in a window service where you don't have to worry about the problem of recycle app pool and e.t.c

The current setup of WebAPI for the ESB is pretty good as it is, because you can easily configure it to run on SSL using a certificate and it will automatically run all the necessary step to make it work for you.

For configuration of WebAPI for the ESB, refer to this link:

https://pservicebus.codeplex.com/SourceControl/changeset/view/5b508e6e7e59#pServiceBus/Src/PServiceBus.Endpoints.WebAPI/services.xml


Let me know if you have any other question.

Thanks,
Aug 12, 2013 at 12:47 AM
Thanks for answer!. The reason for hosting it in IIS is because it's more familiar to me, and I think I can debug the whole process..

I tried to connect the android sample on LAN but it's not working. Maybe Windows 8 is blocking something. Is there any way to log all the details?

Just for testing purposes, if I make a GET request from my browser to http://localhost:8087/ESB/GetSubscribe I get {"Message":"An error has occurred.","ExceptionMessage":"info.Subscriber","ExceptionType":"System.InvalidOperationException","StackTrace":" at PServiceBus.Services.Web.WebMessageBus.ValidateSubscriptionInfo(SubscriptionInfo info) in c:\Users\Cris\Desktop\pservicebus-5b508e6e7e59\pservicebus_5b508e6e7e59\pServiceBus\Src\PServiceBus.Services.Web\WebMessageBus.Commands.cs:line 19\r\n at PServiceBus.Services.Web.WebMessageBus.Subscribe(SubscriptionInfo info) in c:\Users\Cris\Desktop\pservicebus-5b508e6e7e59\pservicebus_5b508e6e7e59\pServiceBus\Src\PServiceBus.Services.Web\WebMessageBus.Commands.cs:line 100\r\n at PServiceBus.WebAPI.Controllers.ESBController.Subscribe(SubscriptionInfo info) in c:\Users\Cris\Desktop\pservicebus-5b508e6e7e59\pservicebus_5b508e6e7e59\pServiceBus\Src\PServiceBus.WebAPI\Controllers\ESBController.cs:line 38\r\n at PServiceBus.WebAPI.Controllers.ESBController.GetSubscribe(SubscriptionInfo info) in c:\Users\Cris\Desktop\pservicebus-5b508e6e7e59\pservicebus_5b508e6e7e59\pServiceBus\Src\PServiceBus.WebAPI\Controllers\ESBController.GET.cs:line 32\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.\u003c\u003ec__DisplayClass13.\u003cGetExecutor\u003eb__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.\u003c\u003ec__DisplayClass5.\u003cExecuteAsync\u003eb__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}

Instead, when I make the same request in LAN
http://192.168.2.101:8087/ESB/GetSubscribe

I get

{"Message":"An error has occurred."}.

Any idea of where is the problem?
Coordinator
Aug 12, 2013 at 1:00 AM
The reason you are getting the exception for the request is show in the stacktrace you posted above. The excepted parameter info.Subscriber is null. The ValidateSubscriptionInfo method throws the exception when your object is invalid. You need to make sure that you are posting the correct data to the GetSubscribe method. Below is what is expected. Make sure to add all the correct querystring to your GetSubscribe, you can also use the Subscribe method instead which uses a POST(you can simply pass a json representation of SubscriptionInfo and it should work fine)
private void ValidateSubscriptionInfo(SubscriptionInfo info) {
            if (info == null) throw new ArgumentNullException("info");
            if (info.Subscriber == null) throw new InvalidOperationException("info.Subscriber");
            if (info.Topic == null) throw new InvalidOperationException("info.Topic");
        }
public class SubscriptionInfo {
        public string Subscriber { get; set; }
        public string Topic { get; set; }
        public string Filter { get; set; }
        public bool Durable { get; set; }
        public bool NeedHeader { get; set; }
        public bool CaseSensitive { get; set; }
        public TransportInfo Transport { get; set; }
    }
Since you installed the ESB from source, you should still be able to debug it by simply launching the solution in visual studio and attaching to the "PServiceBus.Endpoints.WebAPI" process


In regards to not been able to connect using the LAN, make sure you do the above and after that I believe it should work. It works fine for me over my LAN without any extra configuration.

Let me know if you have any other question.

Thanks,
Coordinator
Aug 12, 2013 at 1:04 AM
If you want to find out how to properly call the WebAPI for the ESB, you should look at the psb.js source code:

https://pservicebus.codeplex.com/SourceControl/latest#pServiceBus/Src/PServiceBus.Services.Web/Scripts/psb.js