我已經閱讀了幾個帖子,用戶有這個相同的問題。編譯時,.exe無法從app.config加載任何資源。即使將app.config複製到輸出目錄時也會發生這種情況。app.config被忽略?
具體來說,我有一個Web服務客戶端是無法確定正確的端點配置的問題,即使我靜態編譯它像這樣:
this.ws = new MyServicePortTypeClient("MyServicePort", "http://mysite.com/customer_portal/ws.php");
拋出的異常狀態「系統。 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>
如果無論您是否在app.config中設置了配置,都會拋出相同的異常,在我看來,app.config並未涉及您的實際問題。 – 2010-11-13 02:21:22
如果是這樣的話,它會是什麼?可能有用的更多細節是它是一個Windows服務應用程序。當我通過Visual Studio進行調試時,它工作正常,但是在使用installutil進行安裝後,它給了我這個錯誤。 – Skudd 2010-11-13 02:23:37
你可以向我們展示**你正在使用的app.config嗎?此錯誤很可能是由於該文件中格式錯誤的WCF配置。只是''部分 - 謝謝! –
2010-11-13 07:12:53