3

我有一个小的 sharepoint 项目,它集成到一个更大的 sharepoint 项目中。我的项目使用两个 Web 服务。我已经Web Reference使用VS2010. 我们有两套网络服务——一套用于测试,一套用于生产。当我在本地部署应用程序时,Web 服务设置将写入C:\inetpub\wwwroot\wss\VirtualDirectories\80\我本地计算机上的 web.config 文件。该部分看起来像这样 -

 <applicationSettings>
    <XXX.YYY.Properties.Settings>
      <setting name="XXX_YYY_ZZZ_WS1" serializeAs="String">
        <value>http://<TEST_IPAddress>/WebService/WS1.asmx</value>
      </setting>
      <setting name="XXX_YYY_ZZZ_WS2" serializeAs="String">
        <value>http://<TEST_IPAddress>/WebService/WS2.asmx</value>
      </setting>
    </XXX.YYY.Properties.Settings>
  </applicationSettings>

测试和生产 Web 服务之间的区别只是 IP 地址。当我将 IP 地址更改为生产时,应用程序未使用新值。我不得不返回 VS,Web Reference URLProperties对话框中的更新为正确的生产 url,然后再次重新部署包。这很乏味,因为我不断地从测试切换到生产 Web 服务 url。我希望能够更改 app.config 中的 IP 地址,在浏览器中刷新页面,它应该会选择新的 url。

难道我做错了什么?还有另一种方法可以做到这一点吗?

4

2 回答 2

1

我认为如果您在代码中更改 web 服务 url,那么您将不必重复构建过程。你可以这样改变

WebServiceObjectName webService = new WebServiceObjectName (); 
webService.Uri = [IPaddress or DNS name]
于 2012-04-18T17:27:14.703 回答
0

我们这样做:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IPublicWS"
                openTimeout="00:00:05"
                sendTimeout="00:03:00"
                receiveTimeout="00:10:00"
                closeTimeout="00:00:30"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="262144" maxBufferPoolSize="524288" maxReceivedMessageSize="262144"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="131072" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <!-- Production -->
        <endpoint name="SvLive" address="http://sv.com/PublicWS/PublicWS.svc/PublicWS" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicWS" contract="SV.IPublicWS" />

        <!-- Test -->
        <endpoint name="SvTest" address="http://staging.sv.com/PublicWS/PublicWS.svc/PublicWS" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicWS" contract="SV.IPublicWS" />
    </client>
</system.serviceModel>

​ 然后,要获取此 Web 服务的客户端引用:

public static PublicWSClient Client()
{
#if PRODUCTION
    return new PublicWSClient("SvLive");
#else
    return new PublicWSClient("SvTest");
#endif
}

这被称为:

var sv = PublicWSClient.Client();

这可以防止您描述的任何手动步骤,并允许在准备签入的单个配置文件中捕获测试和实时。

于 2012-07-16T21:47:07.040 回答