我已经阅读了几篇用户遇到同样问题的帖子。编译后,.exe 无法从 app.config 加载任何资源。即使将 app.config 复制到输出目录,也会发生这种情况。
具体来说,我遇到了一个问题,即 Web 服务客户端无法确定正确的端点配置,即使我像这样静态编译它:
this.ws = new MyServicePortTypeClient("MyServicePort", "http://mysite.com/customer_portal/ws.php");
抛出的异常状态为“System.InvalidOperationException:在 ServiceModel 客户端配置部分中找不到引用合同 'MyWebService.MyServicePortType' 的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为没有与此匹配的端点元素合同可以在客户端元素中找到。”
我很茫然,所以任何帮助将不胜感激。
编辑:这是 MyService.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyServiceBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mysite.com/customer_portal/ws.php"
binding="basicHttpBinding" bindingConfiguration="MyServiceBinding"
contract="MyWebService.MyServicePortType" name="MyServicePort" />
</client>
</system.serviceModel>
</configuration>