C# 如何从正在运行的服务中获取WSDL文件?
以下是我如何启动web服务:C# 如何从正在运行的服务中获取WSDL文件?,c#,wcf,wsdl,C#,Wcf,Wsdl,以下是我如何启动web服务: try { //load the shedluer static constructor ServiceHost svh = new ServiceHost(typeof(OrderExecutor)); var tcpbinding = new NetTcpBinding(SecurityMode.None); //remove limits on the max array size var httpLocation
try
{
//load the shedluer static constructor
ServiceHost svh = new ServiceHost(typeof(OrderExecutor));
var tcpbinding = new NetTcpBinding(SecurityMode.None);
//remove limits on the max array size
var httpLocation = "http://" + address + ":1234";
svh.AddServiceEndpoint(typeof(IOrderExecutor), new WSHttpBinding(SecurityMode.None), httpLocation);
ServiceMetadataBehavior smb = svh.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
smb = new ServiceMetadataBehavior();
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
svh.Description.Behaviors.Add(smb);
// Add MEX endpoint
svh.AddServiceEndpoint(
ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexHttpBinding(),
httpLocation + "/mex"
);
svh.Open();
Console.WriteLine("Service mounted at {0}", httpLocation);
Console.WriteLine("Press Ctrl+c to exit");
var re = new ManualResetEvent(false);
re.WaitOne();
svh.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception");
Console.WriteLine(e);
}
没有任何成功
我也试过了
svcutil /serviceName:IOrderExecutor order-executor.exe
结果如下:
Warning: Unable to load a service with configName 'IOrderExecutor'. To export
a service provide both the assembly containing the service type and an executab
le with configuration for this service.
Details:Either none of the assemblies passed were executables with configura
tion files or none of the configuration files contained services with the config
name 'IOrderExecutor'.
Warning: No metadata files were generated. No service contracts were exported.
To export a service, use the /serviceName option. To export data contracts, spe
cify the /dataContractOnly option. This can sometimes occur in certain security
contexts, such as when the assembly is loaded over a UNC network file share. If
this is the case, try copying the assembly into a trusted environment and runnin
g it.
如何从正在运行的WCF服务中获取WSDL文件?您尝试过吗
localhost:1234/IOrderExecutor/?wsdl
试试这个,它可能会起作用你的答案就在这里
// Add MEX endpoint
svh.AddServiceEndpoint(
ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexHttpBinding(),
httpLocation + "/mex"
);
编辑:
httpLocation+“/mex”是获取wsdl的地址。另外,httpGetEnabled的行为必须为true要查看wsdl,您需要启用元数据,并按如下所示设置serviceMetadata
< serviceMetadata httpGetEnabled="**true**" / >
没有针对的结果either@ArsenZahray比什么都不对劲。“…asmx?wsdl”应该是如果你已经正确地部署了,你知道这里会有什么问题吗?wsdl也可以是.svc?wsdl
而不是.asmx?wsdl
,你应该使用服务名而不是接口。这如何回答这个问题?哇,我试过了/wsdl?wsdl/mex?wsdl/mex/wsdl/basic?wsdl/basic/wsdl(我有两个端点,和)但没有尝试/?wsdl..WTF。谢谢帮助。
< serviceMetadata httpGetEnabled="**true**" / >