2014-01-21 25 views
0

我使用Visual Studio 2010在c#中編寫了幾個Web服務。我還有一個Apipgee帳戶並通過包含API的Apigee URL訪問Web服務鍵作爲參數。如何在通過Apigee訪問的C#web服務上更改soap:地址位置

訪問的Web服務的WSDL(通過Apigee),我使用類似於下面的URL:

https://myapi-prod.apigee.net/v1/myapi/Path/To/MyWebService.asmx?wsdl&apikey= {myapikey}

的WSDL成功返回,但綁定信息下(如下圖) ,將顯示Web服務的直接路徑。 Originallty,我沒有選擇這個,但是當添加防火牆規則阻止直接訪問我們的服務器(例如api.mydomain.com)時,我當然阻止了人們使用WSDL的任何請求。

我的問題是如何更改WSDL中的地址位置?像Apigee這樣的服務沒有什麼意義,它只保護WSDL。

<wsdl:service name="MyWebService"> 
    <wsdl:port name="MyWebServiceSoap" binding="tns:MyWebServiceSoap"> 
     <soap:address location="https://api.mydomain.com/Path/To/MyWebService.asmx" /> 
    </wsdl:port> 
    <wsdl:port name="MyWebServiceSoap12" binding="tns:MyWebServiceSoap12"> 
     <soap12:address location="https://api.mydomain.com/Path/To/MyWebService.asmx" /> 
    </wsdl:port> 
    <wsdl:port name="MyWebServiceHttpGet" binding="tns:MyWebServiceHttpGet"> 
     <http:address location="https://api.mydomain.com/Path/To/MyWebService.asmx" /> 
    </wsdl:port> 
    <wsdl:port name="MyWebServiceHttpPost" binding="tns:MyWebServiceHttpPost"> 
     <http:address location="https://api.mydomain.com/Path/To/MyWebService.asmx" /> 
    </wsdl:port> 
    </wsdl:service> 

回答

2

在Apigee,你可以有一個政策,那是你現有的流程,以取代由服務器返回的WSDL文件中的價值的一部分。

例如,在響應路徑中使用javascript策略,可以簡單地執行字符串搜索/替換以替換要更改的值。如果你想要沒有js,那麼你可以使用ExtractVariables和AssignMessage策略完全重寫wsdl。

的JS政策示例代碼:

wsdl = context.getVariable("message.content"); 
wsdl = wsdl.replace("api.mydomain.com", "new-server.com", "g"); 

context.setVariable("message.content", wsdl); 

只是微調上面的查找/替換爲它工作你的情況。

一些參考:

+0

這個作品真的很好 - 你會如何追加API密鑰雖然網址是什麼? – emjx

+0

我有以下幾個不添加參數,但不知道如何獲得請求中提供的實際apikey: 'wsdl = wsdl.replace(「。asmx」,「.asmx?apikey =」,「 g「);用於apikeys的' – emjx

+0

,您將在VerifyAPIKey策略中進行驗證(http://apigee.com/docs/api-services/content/enforce-access-control-using-verifyapikey)。如果您將它傳遞給查詢字符串,請在request.queryparam.apikey中查找它的值。如果您只需要讀取密鑰的值,則還可以使用ExtractVariables策略。 –