Cry*_*ime 12 c# wcf app-config visual-studio-2008
很抱歉这个问题很长...我花了两天时间调试并且有很多笔记......
我有一个WCF数据服务和另一个尝试通过TCP和/或HTTP作为客户端连接到它的进程.
我有一个非常简单的测试客户端应用程序似乎连接正常,但更复杂的生产应用程序无法连接(TCP或HTTP).在这两个客户端项目中,我让Visual Studio 2008使用"添加服务引用"生成app.config,并让它从数据服务中提取元数据.
以下是适用于简单测试客户端的代码:
using Client.MyDataService;
namespace Client
{
class Program
{
static void Main(string[] args)
{
MyDataServiceClient client = new MyDataServiceClient("net.tcp");
client.GetRecords();
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是更复杂的生产客户端的代码:
DataServiceManager.cs:
using MyServer.MyDataService;
namespace MyServer.DataServiceBridge
{
class DataServiceManager
{
MyDataServiceClient dataServiceClient = new MyDataServiceClient("net.tcp");
}
}
Run Code Online (Sandbox Code Playgroud)
在主要过程中:
DataServiceManager d = new DataServiceManager();
Run Code Online (Sandbox Code Playgroud)
这是简单客户端和生产客户端的app.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="net.tcp" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8888/MyDataService"
binding="netTcpBinding" bindingConfiguration="net.tcp" contract="MyDataService.IMyDataService"
name="net.tcp">
<identity>
<userPrincipalName value="COMPUTER_NAME\Username" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在MyServer的bin\Debug \文件夹中是MyServer.exe,app.config.
在MyDataSeriviceHost的bin\Debug \文件夹中是MyDataService.exe,app.config和MyDataSeriviceHost.exe.config.app.config和MyDataSeriviceHost.exe.config是完全相同的.
这是错误消息:
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but
was not handled in user code
Additional information: Could not find endpoint element with name 'net.tcp' and contract
'MyDataService.IMyDataService' in the ServiceModel client configuration section.
This might be because no configuration file was found for your application, or because no endpoint
element matching this name could be found in the client element.
Run Code Online (Sandbox Code Playgroud)
有什么想法发生了什么?谷歌已经筋疲力尽了.:-(
Cry*_*ime 18
解决了
事实证明,我们有一个加载DLL的exe.该DLL包含WCF客户端.编译时,会生成MyServer.dll.config,但由于exe是本机的(不是.NET),因此它不会自动读取.config文件.我们需要手动完成.这个链接允许我手动加载配置并创建一个CustomChannelFactory <>来解决这个问题.
对于需要相同事物的其他人,这里是导致解决方案的链接:http: //www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location. ASPX
我有这种情况,我有
现在Consumer项目在<system.serviceModel>我的app.config的Tag中设置了所有相关的配置,它仍然抛出与上面相同的错误.
我所做的只是将相同的标签添加<system.serviceModel>到我的主项目的app.config文件中,最后我们很高兴.
真正的问题,就我的情况而言,它正在读取错误的配置文件.而不是消费者的app.config,它是指主要的proj的配置.我花了两个小时来弄清楚这一点.
| 归档时间: |
|
| 查看次数: |
43603 次 |
| 最近记录: |