在运行时更新Web服务

时间:2012-08-29 06:31:31

标签: asp.net-mvc-3 salesforce web-reference

我有一个与slaesforce集成的MVC应用程序。它运行良好,salesforce提供了WSDL,它在MVC应用程序中用作/作为Web引用,并成功访问salesforce数据。现在我处于需要使用salesforce沙箱的情况。

所以我有两个从Salesforce生成的WSDL,一个用于生产,另一个用于Sandbox。但是不能同时将两者都添加到MVC项目中,因为它们都具有相同的对象。

我需要做的是在某种情况下更改Webservice Url或其他东西,以便再次使用Production WSDL和另一次使用Sandbox WSDL。

所以它会是这样的

//The Action used in salesforce site to send submit order email
public string SendSubmitOrderEmail(string opportunityId,bool isSandbox)
{
   if(isSandbox)
   {
      SforceService sf = new SforceService();
      sf.Url = "https://test.salesforce.com/services/Soap/";
   }
   else
   {
      SforceService sf = new SforceService();
      sf.Url = "https://login.salesforce.com/services/Soap/";
   }
}     

或者我可以在webconfig中更改webservice设置吗?

<applicationSettings>
<ItineraryBuilder.Properties.Settings>
  <setting name="ItineraryBuilder_SalesForceService_SforceService"
    serializeAs="String">
    <value>https://login.salesforce.com/services/Soap/c/25.0/0DFd00Wa6</value>
  </setting>
</ItineraryBuilder.Properties.Settings>
</applicationSettings>

不知道该怎么做。

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您应该在外部属性文件中设置端点URL(以及其他配置信息,如用户名,密码等),然后您的代码将访问此键值属性文件以检索端点URL和配置信息以连接到销售队伍。

  

URL = HTTPS://test.salesforce.com/services/Soap/

     

username=blah@blah.org.sandbox

     

pasword = blahxxxx12345sxxx

理想情况下,你应该为sandbox / dev(dev.properties)和production(prod.properties)提供单独的属性文件,你的构建系统(maven或类似的)应该根据它的运行位置选择正确的属性文件

您应该尽可能避免对代码进行硬编码或确定代码中的环境。 上述技术应适用于Java,C ++,Python等oop语言。

希望这是有道理的!

阿努普

答案 1 :(得分:0)

全心全意,

在运行时更新Web引用可以正常工作

SforceService sf = new SforceService();
sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"

我做错了什么,“sf”没有传递给用于创建连接的API类。

我在这里得到了另一个问题的解决方案

Update web.config applicationSettings programmatically with C# (MVC)

再次感谢。