【发布时间】:2011-10-27 12:47:12
【问题描述】:
我是开发 Web 服务和客户端服务器应用程序的新手,我无法理解如何从 c# Web 服务生成 WSDL 文件。 我需要 WSDL 文件来生成代理类并将其引用到对应的客户端。
class my_server
{
private static HttpChannel channel;
private static int port = 3000;
private static string serverUri = "myservice";
static void Main(string[] args)
{
Console.WriteLine("Sample server");
StartSoapServer(port);
Console.ReadLine();
StopSoapServer();
}
private static bool Start(int p)
{
try
{
port = p;
channel = new HttpChannel(port);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
RemotingConfiguration.RegisterWellKnownServiceType(typeof(server), serverUri, WellKnownObjectMode.Singleton);
IServerChannelSink sinkChain = channel.ChannelSinkChain;
Console.WriteLine("server created");
}
catch (Exception e)
{
return false;
}
return true;
}
private static void Stop()
{
string[] urls = channel.GetUrlsForUri(serverUri);
if (urls.Length > 0)
{
string objectUrl = urls[0];
string objectUri;
string channelUri = channel.Parse(objectUrl, out objectUri);
ChannelServices.UnregisterChannel(channel);
Console.WriteLine("Server stopped");
}
}
public class server : MarshalByRefObject
{
public server()
{
}
public override object InitializeLifetimeService()
{
return null;
}
public bool initialise()
{
Console.WriteLine("initialise()");
return true;
}
public bool ping()
{
Console.WriteLine("ping");
return true;
}
}
}
显然服务器已创建,并一直运行直到它停止...但是在使用 Storm(http://storm.codeplex.com/) 对其进行测试时:通过添加 http://localhost:3000/myserviceuri 它失败了...我还能如何检查该服务是否正常工作,没有实现客户端?如何从该服务器生成 WSDL 文件?
我曾尝试使用http://wsdlgenerator.codeplex.com/,但显然它仅适用于 WCF 服务...
【问题讨论】:
-
该服务是 .asmx Web 服务吗?
-
@Alex Mendez 它应该是一个远程 API..使用 System.Remoting..
-
因此,如果它不是 Web 服务,您就不能期望获得 wsdl。
标签: c# .net client-server remoting