從 wsdl 創建肥皂 Web 服務客戶端,沒有合同方法 (Create soap web service client from wsdl with no contract methods)


問題描述

從 wsdl 創建肥皂 Web 服務客戶端,沒有合同方法 (Create soap web service client from wsdl with no contract methods)

我很困惑,可能是因為對肥皂服務一無所知。當我創建對當前公共 x12 健康文檔提交服務接口的服務引用時:

http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd

我得到了一些定義肥皂消息正文的類,但我無法獲得客戶端代理

我想用 WCF 構建我的客戶端,但是在我找到的每個示例中,他們都有一個現有的合同來生成代理。我沒有那種奢侈。服務的函數通過肥皂動作調用。

我可以使用類似於 這篇文章但是調用總是被拒絕,因為' nonce 已過期'。

WCF 的示例在其 WSDL 中都有一個很好的合同,所以看起來很簡單,但它是無用的代碼,因為我無法(自動)創建任何接口。例如,Rick Strahl 的博客帖子回答了很多問題,而且看起來很棒如果你有合同信息要打電話。我想遵循他的方法,但在創建客戶端(正確地)時遇到了困難!

所以,我可以在指導下使用 WSE 3 構建一個傳統的肥皂客戶端 來自 MSDN 但不是 我們現在應該使用 WCF 嗎?甚至這裡的帖子標籤都說 WSE 是最後的選擇。

我是否遺漏了有關創建客戶端代理的某些內容?

所以我的問題歸結為:如何才能我為在 WCF 中沒有合同的肥皂服務創建了 Web 服務客戶端代理?

也許我不了解有關調用肥皂服務的一些知識,並且真的需要一些幫助。

[編輯:另一個想法‑我可以自己手動構建合同,從而生成一個代理嗎?不確定對soap Web服務的XML輸出的影響..即調用看起來是否正常]

p>所以我的問題歸結為:如何在 WCF 中為沒有合同的 soap 服務創建 Web 服務客戶端代理?

也許我不明白什麼關於調用肥皂服務,並且真的可以使用一些幫助。

[編輯:另一個想法 ‑ 我可以製作自己的手動構建的合同,從而生成一個代理嗎?不確定對soap Web服務的XML輸出的影響..即調用看起來是否正常]

p>所以我的問題歸結為:如何在 WCF 中為沒有合同的 soap 服務創建 Web 服務客戶端代理?

也許我不明白什麼關於調用肥皂服務,並且真的可以使用一些幫助。

[編輯:另一個想法 ‑ 我可以製作自己的手動構建的合同,從而生成一個代理嗎?不確定對soap Web服務的XML輸出的影響..即調用看起來是否正常]

另一個想法 ‑ 我可以製作自己的手動構建合同,從而生成一個代理嗎?不確定對soap Web服務的XML輸出的影響..即調用看起來是否正常]

另一個想法 ‑ 我可以製作自己的手動構建合同,從而生成一個代理嗎?不確定對soap Web服務的XML輸出的影響..即調用看起來是否正常]


參考解法

方法 1:

You can check my sample project for this wsdl https://bitbucket.org/polacekpavel/servicestacksample/src

Or you can use ChannelFactory for that http://msdn.microsoft.com/library/ms576132(v=vs.110).aspx Assume you have this interface ‑ change it to the real one.

[ServiceContract]               
public interface IMathService
{
    [OperationContract]
    int Add(int a,int b);
}

then you can call it at runtime with custom configuration of ABC(address,binding,contract)

   //define binding 
    //assume your binding using basicHttp, change it if you are using something else
    BasicHttpBinding myBinding = new BasicHttpBinding();           

    //define endpoint url (where service is deployed)
    EndpointAddress myEndpoint = new EndpointAddress("http://localhost:11234/MathService.svc"); //change to real endpoint 

    //Use channel factory instead of generated one
    ChannelFactory<IMathservice> myChannelFactory = new ChannelFactory<IMathservice>(myBinding, myEndpoint); //Change to you WCF interface
    IMathservice mathService= myChannelFactory.CreateChannel();

    //and call it            
    var result = mathService.Add(1,1); //input to your method

    ((IClientChannel)mathService).Close();
    myChannelFactory.Close();

(by Robert Achmannpolacekpavel)

參考文件

  1. Create soap web service client from wsdl with no contract methods (CC BY‑SA 2.5/3.0/4.0)

#wse #soap-client #wcf






相關問題

Windows 2000 下的 WSE 服務器 (WSE Server under Windows 2000)

在 wse 中使用自己的異常,而不僅僅是 SoapException (Using own exceptions in wse, not only SoapException)

從Java調用.NET Web服務(WSE 2/3,WS-Security) (Calling .NET Web Service (WSE 2/3, WS-Security) from Java)

從 WCF 調用 WSE 服務的提示? (Tips for calling WSE service from WCF?)

在 Web 服務 (WSE) 中公開自定義類型(類) (exposing custom types (classes) in a web service (WSE))

在具有自定義類型的 WSE 服務中,構造函數是否在消費客戶端工作? (In WSE services, with custom types, do constructors work on the consuming client's side?)

從 Visual Studio 2005 遷移到 2008 時要注意什麼? (What to look out for when moving from Visual Studio 2005 to 2008?)

通過代理調用 WSE Web 服務 (Calling a WSE web-service though a proxy)

VS 2008 上的 WSE 2.0 SP2 (WSE 2.0 SP2 on VS 2008)

如何在使用 WCF(或 WSE 3)的 Web 服務客戶端應用程序的請求和響應中混合消息編碼類型(文本/MTOM)? (How do I mix message encoding types (Text/MTOM) in the Request & Response of a Web Service client application using WCF (or WSE 3)?)

從 wsdl 創建肥皂 Web 服務客戶端,沒有合同方法 (Create soap web service client from wsdl with no contract methods)

Windows 上的 X.509 證書入門 (Primer for X.509 certificates on Windows)







留言討論