【问题标题】:Creating a WebService C# ASP.Net创建 Web 服务 C# ASP.Net
【发布时间】:2008-11-18 06:48:34
【问题描述】:

代码片段如下

namespace RecruiterWebService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>


    [WebService(Namespace = "http://tempuri.org/") ]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class **Service1** : System.Web.Services.WebService
    {


        [WebMethod]
        public XmlDocument Insert(XmlDocument Jobs)
        { }

        [WebMethod]
        public XmlDocument Update(XmlDocument Jobs)
        { }

        [WebMethod]
        public XmlDocument Delete(XmlDocument Jobs)
        { }

        [WebMethod]
        public XmlDocument Insert(string JobPath)
        { }

        [WebMethod]
        public XmlDocument Update(string JobPath)
        { }

        [WebMethod]
        public XmlDocument Delete(string JobPath)
        { }

        [WebMethod]
        public XmlDocument FeedBack(string UserName, string Password)
        { }


    }
}

我的问题是:-

  1. 如何将 WebService 的名称从 Service1 更改为 Jobs..我尝试这样做,但在添加 WebReference 时却出现异常。

  2. 在此 Web 服务中,我使用的是方法重载,但在添加 WebReference 时使用 aginb,它使用我无法理解的消息属性抛出异常和建议。

  3. 根据您的建议解决了上述两个错误后..我遇到了返回类型的问题。我使用 XMLDocument 作为所有 WEBMethods 的返回类型,但是在将其作为 Web 引用添加到客户端之后,方法的返回类型更改为 XMLNode 我该如何解决这个问题

等待响应的家伙..

【问题讨论】:

    标签: c# asp.net web-services


    【解决方案1】:

    1:如果更改类名,还必须更改 .asmx(或 WCF 的 .svc)页面,该页面有一个(文本)标记为 Service1。右键单击 asmx 和“查看标记” - 它应该类似于:

    <%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="WebService1.Service1" %>
    

    更改 ClassCodeBehind 以匹配您当前的设置。

    2:ws 1-1 不支持重载。您只需添加一个属性,为 SOAP 接口上的每个方法提供一个唯一的名称。但是请注意,这将成为您的代理将看到的方法名称。

    例如,您可能会更改以下消息之一:

        [WebMethod(MessageName = "InsertXml")]
        public XmlDocument Insert(XmlDocument Jobs)
        { ... }
    

    现在更新客户端;你(如果你使用 wsdl.exe 等)可能会有一个InsertXml(...) 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 2011-02-12
      • 2012-06-23
      • 2016-02-07
      • 2014-07-14
      • 1970-01-01
      相关资源
      最近更新 更多