2010-11-05 107 views
0

我使用VS2008,.net 3.5。使用WCF代理將服務引用(WCF,VS2008)添加到外部服務

有一個外部Web服務(這是PHP執行,但不介意實施-.net,Java,PHP和...-)。

在我的項目的csproj,我想服務引用添加到WebService的,我想使用WCF。

當我在VS2008中添加服務引用時,創建了WCF代理。

添加服務引用(外部服務)的任何最佳實踐(模式和實踐)?

的WCF代理生成器(我認爲同樣SvcUtil工具命令)生成這樣的源代碼。也許有趣的是管理生成的代碼(ServiceContractAttribute Namespace =「http://192.168.50.63/WebService」使用IP地址,而OperationContractAttribute(Action =「http://devservername/webservice/SmoBridge.php/login」use servername )

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] 
[System.ServiceModel.ServiceContractAttribute(Namespace="http://192.168.50.63/WebService", ConfigurationName="ServiceEasyVista.WebServicePortType")] 
public interface WebServicePortType { 

    [System.ServiceModel.OperationContractAttribute(Action="http://devservername/webservice/SmoBridge.php/login", ReplyAction="*")] 
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)] 
    [return: System.ServiceModel.MessageParameterAttribute(Name="return")] 
    string login(string SESSION_ID, [System.ServiceModel.MessageParameterAttribute(Name="LOGIN")] string LOGIN1, string PASSWORD, string COMPANY_ACCOUNT); 

更新:。

的Erwyn的大約有故障的WCF通道的正確閉合建議 http://bloggingabout.net/blogs/erwyn/archive/2006/12/09/WCF-Service-Proxy-Helper.aspx

爲什麼ClientBase處置需要扔在故障狀態(或者說,有什麼?關閉和中止的區別?)

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/b95b91c7-d498-446c-b38f-ef132989c154/

回答

1

檢查了這一點:

http://www.sanity-free.com/125/php_webservices_and_csharp_dotnet_soap_clients.html

我認爲這是一個複雜的技術。

問候,

了Mazhar卡里米

+1

但據我所知,使用「添加Web引用」選項不使用WCF。 – 2010-11-05 09:32:49

+0

請閱讀完整的文章,在這種情況下我們也使用相同的技術。 – 2010-11-05 09:42:01

+0

thx,另一個參考使用.NET的任何Web服務實現的最佳實踐(不僅PHP,也是.net WCF服務,Java ...) – Kiquenet 2010-11-05 10:32:14

1

我不知道爲什麼會有任何特別的最佳實踐周圍添加引用。話雖如此,Visual Studio中的「刷新引用」命令(右鍵單擊現有服務引用)有時效果不佳,因此可以更輕鬆地手動使用svcutil命令,並且在您的文件中有.bat文件更新服務參考的解決方案(svcutil是「添加服務參考」在幕後使用的內容)。

另外,如果你在引用該服務返回一個數組,你可以得到WCF自動把它變成一個通用的清單(或一些其他類型) - 這可能會使事情變得更容易。

+0

VS使用WCF代理生成器(自定義工具),可能會非常有趣的管理WCF代理和其他方面的代碼。 – Kiquenet 2010-11-05 10:26:07