3

以下是我启动 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 = "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);
} 

该服务启动并正常工作,Visual Studio 可以连接到它并创建一个工作客户端。

但是,我需要一个 WSDL 文件来使其与 PHP 互操作。

我试过了

http://localhost:1234?wsdl
http://localhost:1234/IOrderExecutor?wsdl
http://localhost:1234/IOrderExecutor.wsdl

没有任何成功。

我也试过

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 文件?

4

3 回答 3

3

你试过 localhost:1234/IOrderExecutor/?wsdl

试试这个它可能有效

于 2013-05-16T21:14:37.937 回答
0

你的答案就在这里

// Add MEX endpoint

svh.AddServiceEndpoint(
            ServiceMetadataBehavior.MexContractName,
            MetadataExchangeBindings.CreateMexHttpBinding(),
            httpLocation + "/mex"
            );

编辑:httpLocation + "/mex" 是您获取 wsdl 的地址。也行为 httpGetEnabled 必须为真

于 2013-05-16T21:30:45.743 回答
0

要查看 wsdl,您需要启用 MetaData 来设置 serviceMetadata,如下所示。

< serviceMetadata httpGetEnabled="**true**" / >
于 2018-02-04T09:51:20.967 回答