【问题标题】:Need to create service interface class for WCF service.需要为 WCF 服务创建服务接口类。
【发布时间】:2017-08-15 20:17:41
【问题描述】:

这是我尝试生成的代码文件的 sn-p。这是一个比较老的WCF项目,所以不太熟悉。对于新的服务项目,我只需右键单击并选择更新服务引用。

using System;
`//-------------------------------------------------------------------------
-----
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.269
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------
----


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", 
"4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = 
"IBusinessService")]
[CLSCompliant(false)]
public interface IBusinessService
{

[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IBusinessService/Receive_Replenishment_Request", ReplyAction = "http://tempuri.org/IBusinessService/Receive_Replenishment_RequestResponse")]
int Receive_Replenishment_Request(System.Nullable<int> Module, System.Nullable<int> Level, System.Nullable<int> Side, System.Nullable<int> Row, string User);

此文件与具有 [ServiceContract] 属性的 BusinessService.cs 和 IBuesinessService.cs 位于单独的项目中。

是否有我必须运行的工具来生成服务引用类?我需要更新此服务参考。

【问题讨论】:

  • 不清楚你想做什么。你想生成定义服务的接口吗?还是要生成消费者代码?

标签: c# visual-studio wcf


【解决方案1】:

据我所知,“添加服务参考”窗口只是 Svcutil 的包装器(或者它们调用相同的 API)。您可以从命令提示符处执行该工具。

如果您要为实际运行和公开元数据生成客户端的服务,那么简单

svcutil http://service/metadataEndpoint

生成“代理”,即构成服务客户端的类和数据类型。

如果您无法运行该服务,或者它无法公开元数据,我想您需要将元数据从包含该服务的程序集中导出到 .wsdl 和 .xsd 文件:

svcutil.exe ServiceAssembly.dll

然后从这些文件中生成一个客户端:

svcutil.exe YourServiceName.wsdl

另见How to generate WCF service with SvcUtil.exe

【讨论】:

  • 所以看起来这不是一个真正的服务引用,而只是一个接口。而且我不确定它之前是如何创建的?这个svcutil会创建接口文件吗?
  • 我已经更改了答案中的第二句话。是的,Svcutil.exe 将生成一个代表服务的接口,以及一个充当该服务客户端的代理类。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-20
  • 1970-01-01
  • 2013-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多