问题
can't I expose my methods as webmethods in a winform and have other clients call them as webservice? Basicall I am trying to get my winform app to host a webservice without asp.net or iis.
I am trying to get a ^%&^& blackberry to communicate with my winform app....tried for hours looking for some other way of getting the two to talk without http webservice.
I was looking at UDP but && BB does not provide any documentation for Visual Studio development other than webservice.
回答1:
One thing many people have a problem with is they forget that they need to add a firewall rule or foreword a port to allow outside connection to the endpoint when trying to communicate from a hand-held device that is using the carrier's internet connection (rather than wifi). it could be completely missed since the blackberry is sitting right next to you and you don't think of it as an outside caller.
if that's not the case try a WCF hosted app
You can expose your service using a WCF endpoint.
from http://msdn.microsoft.com/en-us/library/ms731758.aspx
// Host the service within this EXE console application.
public static void Main()
{
// Create a ServiceHost for the CalculatorService type and use
// the base address from config.
ServiceHost hostDefault = new ServiceHost(typeof(CalculatorService));
int manualFlowControlLimit = hostDefault.ManualFlowControlLimit;
basicHttpBinding portsharingBinding = new basicHttpBinding();
hostDefault.AddServiceEndpoint(typeof( CalculatorService ),portsharingBinding,"http://localhost/MyService" );
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
{
// Open the ServiceHost to start listening for messages.
serviceHost.Open();
// The service can now be accessed.
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.ReadLine();
// Close the ServiceHost.
serviceHost.Close();
}
}
回答2:
Sort of. You can host a SOAP service using WCF, but I'm not sure if that's a great architecture.
来源:https://stackoverflow.com/questions/1083486/exposing-methods-as-web-service-operations-in-winform