問題描述
從 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 Achmann、polacekpavel)