I have added url in my Info.plist and trying to handle incoming url like described in this article.
I'm trying to add this code
public override void WillFinishLaunching(NSNotification notification)
{
NSAppleEventManager.SharedAppleEventManager.SetEventHandler(this, new ObjCRuntime.Selector("handleGetURLEvent:withReplyEvent:"), AEEventClass.Internet, AEEventID.GetUrl);
}
[Export("handleGetURLEvent:withReplyEvent:")]
private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent)
{
Logger.Info("Calling url on running app");
}
It all works fine, when my application is launched and somebody clicks on a URL (containing this custom scheme).
However, in the case, if my app isn't started then system start is (which is good). Unfortunately, handleGetURL() isn't called.
Related
I am trying to create a WebHookHandler for Webhooks send from WordPress WooCommerce in ASP.NET C#.
I started with creating a ASP.NET C# Azure API App WebApplication Project and adding the relevant references (Microsoft.AspNet.WebHooks.Common, Microsoft.AspNet.WebHooks.Receivers, Microsoft.AspNet.WebHooks.Receivers.WordPress). Added the WebHookConfig, WordPressWebHookHandler and registered the WebHookConfig in the GlobalAsax.
I then published the application as an Azure App Service.
My WordPressWebHookHandler is still the default of the examples and looks like this:
public class WordPressWebHookHandler : WebHookHandler
{
public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
{
// make sure we're only processing the intended type of hook
if("WordPress".Equals(receiver, System.StringComparison.CurrentCultureIgnoreCase))
{
// todo: replace this placeholder functionality with your own code
string action = context.Actions.First();
JObject incoming = context.GetDataOrDefault<JObject>();
}
return Task.FromResult(true);
}
}
When testing a User Creation WebHook in WooCommerce I can see the request in the log as below.
But unfortunately it is never received while debugging and I see below error.
I am thinking maybe I need a custom WebHook instead of the WordPress specific one as this is a WooCommerce Webhook. Or possibly it is handled wrong in the routing and ends up in another controller.
Any help is much appreciated.
Your WebHookReceiver is wrong
There is a mismatch of expecting HTML Form Data, when in fact it should be expecting JSON.
WordPressWebHookHandler is still the default
This is what is causing your error. If you look at the WordPressWebHookReceiver, the ReceiveAsync() method implementation, calls out to ReadAsFormDataAsync() method, which is not what you want, as your Content-Type is json. So, you want to be doing ReadAsJsonAsync().
Solution: Don't use the WordPressWebHookReceiver and switch it to another one that will call ReadAsJsonAsync().
Looking at the code
I am thinking maybe I need a custom WebHook instead of the WordPress specific one as this is a WooCommerce Webhook.
You had the right idea, so I dug up some of the code to explain exactly why this was happening.
The code block below is the ReceiveAsync() method that is overridden in the WordPressWebHookReceiver. You can see that it is calling the ReadAsFormDataAsync() which is not what you want...
public override async Task<HttpResponseMessage> ReceiveAsync(
string id, HttpRequestContext context, HttpRequestMessage request)
{
...
if (request.Method == HttpMethod.Post)
{
// here is what you don't want to be called
// you want ReadAsJsonAsync(), In short, USE A DIFFERENT RECEIVER.
NameValueCollection data = await ReadAsFormDataAsync(request);
...
}
else
{
return CreateBadMethodResponse(request);
}
}
A quick search through the repository for classes that call the ReadAsJsonAsync() method, shows that the following recievers implement it:
DynamicsCrmWebHookReceiver
ZendeskWebHookReceiver
AzureAlertWebHookReceiver
KuduWebHookReceiver
MyGetWebHookReceiver
VstsWebHookReceiver
BitbucketWebHookReceiver
CustomWebHookReceiver
DropboxWebHookReceiver
GitHubWebHookReceiver
PaypalWebHookReceiver
StripeWebHookReceiver
PusherWebHookReceiver
I assumed that the CustomWebHookReceiver would fit your requirements, so can grab the NuGet here. Otherwise you can implement your own, or derive it from this class, etc.
Configuring a WebHook Recevier
(Copied from the Microsoft Documentation)
Microsoft.AspNet.WebHooks.Receivers.Custom provides support for
receiving WebHooks generated by ASP.NET WebHooks
Out of the box you can find support for Dropbox, GitHub, MailChimp,
PayPal, Pusher, Salesforce, Slack, Stripe, Trello, and WordPress but
it is possible to support any number of other providers
Initializing a WebHook Receiver
WebHook Receivers are initialized by registering them, typically in
the WebApiConfig static class, for example:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
...
// Load receivers
config.InitializeReceiveGitHubWebHooks();
}
}
There is a problem with the data format that you send in your request. You must use format of HTML Form as your error message said.
Proper POST data format is described here: How are parameters sent in an HTTP POST request?
Don't forget to set Content-Length header and correct Content-Type if your library doesn't do it. Usually the content type is application/x-www-form-urlencoded.
I would like to make some additions to Svek's answer as I now got my Proof-of-concept completed and understand a bit more about the receivers.
His answer pointed me in the right direction, but needs a little addition.
WordpressWebHookReceiver
Can take in Wordpress Webhooks of type HttpPost. This does not work with Woocommerce as Woocommerce sends Json Webhook messages and will fail the HttpPost validation which is build into the WordpressWebHookReceiver class.
CustomWebHookReceiver
Can take in custom ASP.NET Webhooks. The custom ASP.NET webhooks have a specific partner for validation which includes but is not limited to the 'ms-signature'. Even adding the header will not suffice as the signature is also used in a different way from out of the box Woocommerce to encrypt the message. Basically coming to a point that you can't integrate Woocommerce with the CustomWebHookReceiver without changing the Webhook classes of Woocommerce.
GenericWebHookReceiver
This is the receiver you want, which accepts basically a generic set of Json data and will be able to use the "code" query parameter to verify the secret which you can add in the web.config of your asp.net api application. I used this receiver to finish the Proof-of-concept and got both the signature validation as well as the deciphering of the message working right of the bat.
My basic class which I will start to build into a real solution can be viewed below and changes the JObject into a dynamic object in the methods I call from the class. As you can see I have two methods currently added, one for the customer create and one for the order create to call the respective methods which do an insert into Dynamics 365 (former CRM).
public class GenericJsonWebHookHandler : WebHookHandler
{
public GenericJsonWebHookHandler()
{
this.Receiver = "genericjson";
}
public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
{
var result = false;
try
{
// Get JSON from WebHook
var data = context.GetDataOrDefault<JObject>();
if(context.Id != "crcu" && context.Id != "cror")
return Task.FromResult(true);
if (context.Id == "crcu")
{
result = WoocommerceCRMIntegrations.Entities.Contact.CreateContactInCRM(data);
}
else if (context.Id == "cror")
{
result = WoocommerceCRMIntegrations.Entities.Order.CreateOrderInCRM(data);
}
}
catch (Exception ex)
{
result = false;
}
return Task.FromResult(result);
}
}
I have a program that utilize a web service. When this web service is tested on its own (run on ie AS .asmx) runs fine but when tried to be called from inside the web form it produces the following error:
Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.
The web servce is:
public Check1 () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public void check2(string destination)
{
Server.Transfer(destination);
}
}
And the web form from which is called is:
protected void Button1_Click1(object sender, EventArgs e)
{
localhost.Check1 new2 = new localhost.Check1();
new2.check2("Ipal_apoth_page.aspx");
}
A web service is intended to be a data interface, not a web page server, which is why XML is expected. Web service protocols use XML format for their communications, e.g. WSDL or SOAP. The .aspx page you attempt to transfer the processing to will return HTML.
It may be that when you tried it in a browser, the browser was permissive enough to interpret the repsonse from the web service in the way you wanted even though that is not how it is meant to be used.
A better thing to practise with would be something simple like adding two numbers.
I have a win phone and I got a new requirement to put google analytic to log app events.
I added everything I found over net but my client saying that he is not seeing any log. So what I using is
GoogleAnalytics.EasyTracker.GetTracker().SetStartSession(true);
Used this line of code on app startup. And than
public void SendEvent(string category, string action, string label, int value)
{
GoogleAnalytics.EasyTracker.GetTracker().SendEvent(category, action, label, value);
}
this method to log events. Is there something wrong I am doing?
I have a c++ client publishing Corba messages to a c# server via omniOrb. I have registered a PortableInterceptor with the Orb at the server end and can intercept messages.
In debug I get a ServerRequestInfo message in the intercept and In debug watch window can see the all the way down to the RemoteEndPort with the IP of the client. A lot of these classes however have private members which I can't access in the code.
How do I do it?
Here is my code
// register the OrbInitialiser here in some code
omg.org.CORBA.OrbServices orb = omg.org.CORBA.OrbServices.GetSingleton();
orb.RegisterPortableInterceptorInitalizer( new LT.Quantifi.BrokerOrbInitialiser());
orb.CompleteInterceptorRegistration();
// register the Inteceptor in the OrbInitialiser here
public class BrokerOrbInitialiser : omg.org.PortableInterceptor.ORBInitializer
{
public void post_init(ORBInitInfo info)
{
BrokerRequestInterceptor serverRequests = new BrokerRequestInterceptor();
info.add_server_request_interceptor(serverRequests);
}
}
// Inteceptor catches messages here
Public class BrokerRequestInterceptor : omg.org.PortableInterceptor.ServerRequestInterceptor
{
.
.
public void receive_request_service_contexts(ServerRequestInfo ri)
{
Console.WriteLine("I catch messages here");
}
.
.
}
There is no standard way to get access to that information in CORBA. Some implementations do have a custom way to get some information, for example TAO has a transport current object you can get access to. At the moment the call has been received using IIOP you can narrow that to a IIOP Transport Current which than gives you that information. Looks you need an extension for the C# ORB to have a similar extension
After my previous question HERE, I found the solution (well, part of it).
Here's the code for Java part:
#WebService
public class MyWebService
{
#WebMethod
public String myMethod()
{
return "Hello World";
}
#WebMethod
public int Add(#WebParam(name="a") int a,
#WebParam(name="b") int b)
{
return a + b;
}
public static void main(String[] args)
{
String address = "http://127.0.0.1:8023/_WebServiceDemo";
Endpoint.publish(address, new MyWebService());
System.out.println("Listening: " + address);
}
}
And Here is the Silverlight part:
private void SearchResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MyWebServiceClient proxy = new MyWebServiceClient();
proxy.AddCompleted += proxy_AddCompleted;
proxy.AddAsync(2, 3);
}
void proxy_AddCompleted(object sender, AddCompletedEventArgs e)
{
txtSearch.Text = e.Result.ToString();
}
But when I run this, e.Result throws an exception.
What am I missing/ How should I solve it?
Note that this code runs perfectly in C# Console application (when it's not async). But when I run the async code, it doesn't work.
Thanks in advance.
I guess you are getting a System.ServiceModel.CommunicationException when trying to access the Java Webservice from Silverlight.
There is nothing basically wrong with your code, and it should also work with async calls in C# Console App.
The main problem is that Silverlight (as a browser plugin) enforces some security restrictions that prevent a Silverlight Application to talk to another server than the one loaded from (defined by server name and port) without further configuration. This behaviour can be configured as described here (also search for "silverlight cross-domain calls" or "silverlight cross domain policy").
This restrictions (normally) do not apply to desktop or console applications so they'll work fine with the same web service.
To make your code work you need to host the Silverlight Application inside the same "project" / website than your webservice (so I suppose, the self-hosting webservice won't work and you need to switch to Java web project where the webservice is to be hosted). As the Silverlight Application basically consists of an enclosing HTML file plus the referenced binaries, you can host it on any server, e.g. Apache Tomcat.
Hope this helps.