【发布时间】:2009-01-06 20:42:44
【问题描述】:
我有一个托管 WCF 服务的控制台应用程序:
已更新此代码以运行 app.config 文件,而不是以编程方式对其进行初始化
Uri baseAddress = new Uri("http://localhost:8000/ChatServer/Service");
ServiceHost myHost = new ServiceHost(typeof(ClientServerChat.ChatServer), baseAddress);
myHost.AddServiceEndpoint(typeof(IChat), new WSHttpBinding(), "ChatService");
ServiceMetadataBehavior mb = new ServiceMetadataBehavior();
ServiceBehaviorAttribute attrib = (ServiceBehaviorAttribute)myHost.Description.Behaviors[0];
attrib.IncludeExceptionDetailInFaults = true;
mb.HttpGetEnabled = true;
myHost.Description.Behaviors.Add(mb);
myHost.Open();
控制台应用程序编译并运行。 svcutil 运行完美。
Svcutil 完美运行新服务代码并生成客户端代码和输出文件
我正在通过 Visual Studio 命令提示符调用 svcutil,如下所示:svcutil.exe http://localhost:8000/ChatServer/Service
它会生成这个 output.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IChat" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/ChatServer/Service/ChatService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IChat"
contract="IChat" name="WSHttpBinding_IChat">
<identity>
<userPrincipalName value="Bedroom-PC\Roberto" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
连同捆绑的客户端代码(与输出文件在同一目录中,我应该添加),我应该能够使用以下代码调用服务:
ChatClient client = new ChatClient();
svcutil 的新输出(代码和配置)仍然抛出此异常。
但它抛出一个异常说:
“在 ServiceModel 客户端配置部分中找不到引用合约“IChat”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端中找不到与此合约匹配的端点元素元素。”
有趣的是,将相同的服务引用添加到客户端项目时,Visual Studio 2008 会崩溃。
VS2008 仍然会因更新代码而崩溃。
它会找到服务,得到所有的操作,什么不是。当我点击添加时,它崩溃了。
有人知道怎么回事吗??
提前致谢
罗伯托
【问题讨论】:
标签: c# visual-studio wcf