我正在尝试使用svcutil.exe创建WCF客户端文件。我运行托管我的wcf服务库的wpf应用程序。从visual studio命令提示符2010运行svcutil时出现以下错误:
WS-Metadata Exchange错误 URI:net.tcp:// localhost:50100 / duplex 元数据包含无法解析的引用:'net.tcp:// localhost:50100 / duplex'。
有人可以解释我的配置文件有什么问题,以及如何使用svcutil.exe成功生成客户端文件?
这是我的svcutil命令(我在启动服务后运行此命令):
c:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC> svcutil.exe net.tcp:// localhost:50100 / duplex / d:c:\ temp
这是我托管wcf服务库的wpf应用程序的app.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="baseAddress" value="net.tcp://localhost:50100/duplex"/>
</appSettings>
<system.serviceModel>
<!--<bindings />-->
<client />
<services>
<service name="TrackRejectCommunication.RejectService"
behaviorConfiguration="RejectServiceBehavior">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="DuplexNetTcpBinding_IRejectService"
name="netTcp"
contract="TrackRejectCommunication.IRejectService" />
<endpoint name="NetTcpMetadataPoint"
address="mexTcp"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="DuplexNetTcpBinding_IRejectService"
sendTimeout="00:00:10"
portSharingEnabled="false">
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="RejectServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:50103/Metadata/Duplex" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
我通过wpf应用程序中的配置管理器获取基址。我使用以下代码在我的wpf应用程序中启动服务:
RejectService rejectService = new RejectService();
//start the reject service.
HostStartup.StartService(rejectService);
StartService代码:
Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
//Instantiate new ServiceHost with the singleton instance being passed in
myServiceHost = new ServiceHost(instance, baseAddress);
//Open myServiceHost
myServiceHost.Open();
答案 0 :(得分:0)
当使用svcutil为通过“myServiceHost = new ServiceHost(instance,baseAddress);”启动的单例服务创建wsdl / proxy时,我遇到了类似的问题。通过临时注释掉创建/打开ServiceHost实例的代码,然后运行svcutil来创建wsdl,然后将代码恢复为原始格式,我能够解决这个问题。似乎无论svcutil做什么都与代码内实例化的ServiceHost不兼容。
作为参考,我遇到的特定错误是:
警告:加载要导出的服务类型时出错:...
详细信息:...的类型初始化程序引发了异常。