app.config 被忽略?

发布于 2024-10-02 09:06:05 字数 2224 浏览 0 评论 0原文

我读过几篇用户遇到同样问题的帖子。编译后,.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>

I have read several posts where users were having this same issue. When compiled, the .exe is unable to load any resources from app.config. This is occurring even when the app.config is copied to the output directory.

Specifically, I'm having an issue with a web service client being unable to determine the proper endpoint configuration, even if I statically compile it in like this:

this.ws = new MyServicePortTypeClient("MyServicePort", "http://mysite.com/customer_portal/ws.php");

The exception thrown states "System.InvalidOperationException: Could not find default endpoint element that references contract 'MyWebService.MyServicePortType' 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 contract could be found in the client element."

I'm at a loss so any help would be appreciated.

Edit: Here's the 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南街九尾狐 2024-10-09 09:06:05

EXE 从 FileName.exe.config 获取设置,而不是从 App.config

FileName.exe.config 应在编译代码时自动生成,并放置在EXE 本身。

检查包含 EXE 的文件夹。您是否在其中看到 FileName.exe.config

(由于长度和格式而作为答案发布)

EXE is taking the settings from FileName.exe.config, not from App.config

The FileName.exe.config should be auto generated when compiling the code, and placed alongside the EXE itself.

Check the folder where you have the EXE.. do you see FileName.exe.config in there?

(Posted as answer due to length and formatting)

明媚殇 2024-10-09 09:06:05

嗯,根据大家提供的信息,我弄清楚了。

问题是 installutil.exe 尝试使用自己的配置,而不是由服务创建的配置。在这种情况下,它尝试加载 C:\Windows\Microsoft.NET\Framework\v2.0...\InstallUtil.config。

现在我已经弄清楚了这一点,我可以使用它并使其正常工作。

谢谢你们!

Well, I figured it out with the help from the information provided by everyone.

The issue is that installutil.exe is trying to use its own config, instead of the one created by the service. In this case, It's trying to load C:\Windows\Microsoft.NET\Framework\v2.0...\InstallUtil.config.

Now that I've figured that out, I can work with it and get it to work correctly.

Thanks, y'all!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文