[英]How to change soap:address location on a C# web-service accessed via Apigee
我使用Visual Studio 2010在c#中編寫了幾個Web服務。我還有一個Apipgee帳戶,並通過Apigee URL訪問Web服務,包括API密鑰作為參數。
訪問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>
在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);
只需微調上面的搜索/替換它就可以在你的情況下工作。
一些參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.