2012-08-29 84 views
0

我有一個MVC應用程序,我與slaesforce集成。它運行良好,salesforce提供了WSDL,它用於/作爲MVC應用程序中的Web引用併成功訪問salesforce數據。現在,我需要使用salesforce沙盒。在運行時更新web服務

所以我有兩個WSDL生成從Salesforce一個生產和另一個沙箱。但是不能同時添加到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更改Web服務設置?

<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> 

不知道該怎麼辦。

感謝您的任何幫助。

回答

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)

感謝。

0

您應該在外部屬性文件中設置端點url(以及其他配置信息,如用戶名,密碼等),然後您的代碼將訪問此鍵值屬性文件以檢索連接的端點url和配置信息銷售人員。

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

[email protected]

pasword = blahxxxx12345sxxx

理想情況下,你應該爲sandbox/dev(dev.properties)和production(prod.properties)提供單獨的屬性文件,並且你的構建系統(maven或者類似的)應該根據它運行的位置選擇正確的屬性文件。

您應該儘可能避免硬編碼url或確定代碼中的環境。 上述技術應該適用於像Java,C++,Python等OOP語言。

希望這是有道理的!

阿努普

+0

對不起,我沒有得到,如果我在外部文件中設置屬性,我將如何更新網絡參考網址與它? –

+0

我假設你正在使用c#。這個問題 - 答案(http://stackoverflow.com/questions/485659/can-net-load-and-parse-a-properties-file-equivalent-to-java-properties-class)可能會指出你在正確的方向。 – Anup