简体   繁体   中英

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. But I didnt understand clearly how it works.

Can you show me how the below code would be if converted to 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合同无关紧要,使用可选参数的实际语义是多余的(它们仍被归类为必需参数 - 即所有参数)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM