将数据从php发送到c#桌面应用程序
I am looking into doing a project which would involve php and c#. What I need to do is from PHP the user can perform a certain task and once php has processed some information, this information needs to be sent to a c# application and c# can do some other work with the information provided.
The c# application would most likely work from the same server that the php web app is running from but it should work if they are on completely separate servers.
I guess I could send some XML from php to whatever IP address that the c# program running on, but have no idea how I would get php to do the sending and the c# app to do the listing for the data.
Any help would be greatly appreciated.d
我正在研究一个涉及php和c#的项目。 我需要做的是从PHP用户可以执行某项任务,一旦php处理了一些信息,这些信息需要发送到c#应用程序,c#可以用提供的信息做一些其他工作。 p>
c#应用程序很可能来自运行php web应用程序的同一台服务器,但如果它们位于完全独立的服务器上,它应该可以正常工作。 p>
我想我可以将一些XML从php发送到运行c#程序的任何IP地址,但不知道如何让php发送和c#app做 数据列表。 p>
我们非常感谢任何帮助。 p> div>
SOAP
In one acronym, you have the solution to (almost) any interoperability problem in your life.
"Simply" define a web service running in a desktop application (it is possible but it's not that straightforward) and instantiate a PHP SoapClient.
XML (pure)
Of course you can send direct XML input to your desktop application. This makes use of .NET Socket (System.Net.Sockets
) and PHP socket I/O (fsockopen
). You can create your application-specific protocol and inject the XML data.
Recommended if you are already very familiar with XML and comfortable to sockets. Unrecommended if you want a higher level of reusability.
You don't specify the nature of the data you're sending but if you're sending it across the web, then using language-independent methods such as XML, JSON, web services and the like means your server-side languages are largely irrelevant.
If you're sending something like huge movie files, however, then you'll probably be better off using FTP or similar.
You could open a WCF channel in the C# service and then call into it with PHP.
You should host a self host WCF service in your desktop application and call the services from your php application.
using System.ServiceModel;
using System.ServiceModel.Description;
sample code:
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
string SayHello(string name);
}
public class HelloWorldService : IHelloWorldService
{
public string SayHello(string name)
{
return string.Format("Hello, {0}", name);
}
}