[英]Converting .asmx to WCF
I'm developing a .NET 3.5 webservice using .asmx pages, but the fact that i cant use optional parameters in the GET and POST requests is making me think in switch my application to WCF. 我正在使用.asmx页面开发.NET 3.5 Web服务,但我无法在GET和POST请求中使用可选参数,这让我想到将我的应用程序切换到WCF。 But I didnt understand clearly how it works.
但我不清楚它是如何工作的。
Can you show me how the below code would be if converted to 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.