Ste*_*ven 4 web-services web-reference web-config asmx
我正在努力如何配置网址引用的URL.
情况就是这样.我有:旧的asp.net webservices <----- c#项目编译成dll <-----引用dll的网站(c#项目以前不在那里,但我将所有代码重构为一个单独的项目)
因此,网站代码调用c#项目的代码来获取结果,然后调用Web服务.
在c#项目中添加Web引用时,我输入了webservices的URL位置(http://192.168.10.1/TestServices.asmx?wsdl.然后生成包含webservices的url的app.config文件.
如果我将Web引用设置为静态,则不应使用配置,这是有效的.现在,如果我将web引用设置为动态,则应该使用配置,但由于这是一个正在编译为dll的项目,并且该网站没有app.config,而是我将配置从app.config设置为my web.config appSettings节点,我将URL更改为另一个Web服务(http://192.168.10.2/TestServices.asmx.
在c#项目中添加Web引用时,网站仍然会从Web引用指向的旧URL获取结果,因此看起来在URL Behavious设置为Dynamic时未使用配置设置.
我可能在这里错过了一些微不足道的东西吗?
这是app.config中的内容:
<applicationSettings>
<XXXX.Properties.Settings>
<setting name="XXXX_TestServices_TestServices" serializeAs="String">
<value>http://192.168.10.1/TestServices.asmx</value>
</setting>
</XXXX.Properties.Settings>
</applicationSettings>
Run Code Online (Sandbox Code Playgroud)
这是我放在web.config中的内容:
<appSettings>
<add key="XXXX_TestServices_TestServices" value="http://192.168.10.2/TestServices.asmx" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
所以,现在它总是有趣和信息/教育当在问题的打字和双重检查和搜索相关的问题,你最终自己解决问题..无论如何我发布它的答案,因为我没有找到一个确切的答案通过结合其他2个问题和博客文章.
有些资源提到您需要创建设置并需要在代码中更改Web服务代理对象的url属性.这不是必需的,您只需要以正确的方式编辑您的Web配置.
该URL不会像web.config的appSettings部分一样直接从网站引用Web服务.
相反,您需要从dll项目中生成的app.config复制整个配置代码,包括定义用于设置正确URL的applicationSettings节点的sectiongroup配置.
对于此特定示例,其中包含web.config中的以下配置代码:
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XXXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
...
</configuration>
<applicationSettings>
<XXXX.Properties.Settings>
<setting name="XXXX_TestServices_TestServices" serializeAs="String">
<value>http://192.168.10.2/TestServices.asmx</value>
</setting>
</XXXX.Properties.Settings>
</applicationSettings>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9378 次 |
| 最近记录: |