[英]Converting .asmx to WCF
我正在使用.asmx頁面開發.NET 3.5 Web服務,但我無法在GET和POST請求中使用可選參數,這讓我想到將我的應用程序切換到WCF。 但我不清楚它是如何工作的。
如果轉換為WCF,你能告訴我下面的代碼是怎么樣的嗎?
[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService]
public class ws :WebService
{
#region WebMethods
//Parameters shoud be optional but it isnt possible in .asmx .NET 3.5
[WebMethod]
public XmlNode GetResult(string param1(=null), string param2(= null))
{
MyClass myClass = new MyClass();
//Get a xml string
string output = myClass.GetXmlString(param1, param2);
//Load this xml
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(output);
//Return this xml
return xmlDocument.DocumentElement;
}
#endregion
}
WSDL無法描述可選參數,因此如果您使用ASMX或WCF合同無關緊要,使用可選參數的實際語義是多余的(它們仍被歸類為必需參數 - 即所有參數)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.