[英]Best way to create WCF “server side code” service from existing WSDL
我有一個現有的wsdl和xsd文件。 現在,我想基於現有的WSDL創建WCF“服務器端代碼”服務。 我知道svcutil.exe會生成主機(客戶端)代碼。 我不要客戶端。 請,有人可以幫我嗎?
使用xsd /c /l:cs /n:Namespace.You.Want FilenameRequest.xsd FilenameResponse.xsd
用約定的XML合同生成c#類。 您將擁有類似ResponseClass.cs
和RequestClass.cs
然后創建您的服務,將生成的Request類作為message參數傳遞。 強制服務使用XmlSerializer而不是DataContractSerializer 。 像這樣:
[ServiceContract, XmlSerializerFormat(Style = OperationFormatStyle.Document,
Use = OperationFormatUse.Literal)]
public interface IService
{
[OperationContract()]
ResponseClass YourRequestOperation(
[MessageParameter(Name="NameInAgreedContract")] RequestClass rq);
}
然后創建接口的實現。 部署它。 利潤。
在我的情況下,客戶端將生成一個非常具體的wsdl文件,該文件是他給我的,其中包含類定義所在的其他xsd文件。 我只想要接口頭的結構(System.SerializableAttribute,XmlTypeAttribute ...),因為wsdl文件中未提供DataContract和DataMember的結果。 當我使用svcutil時,我只是與wsdl文件對齊了一點,但是區別仍然是綁定,端口名。 前綴也像“ intf”而不是“ tns”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.