简体   繁体   English

创建一个WebService C#ASP.Net

[英]Creating a WebService C# ASP.Net

The Code Snippet is as follwos 代码段如下所示

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)
        { }


    }
}

My Questions are:- 我的问题是:

  1. How can I change the name of the WebService from Service1 to lets say Jobs..I tried doing this but then while adding the WebReference its was giving Exception. 如何将WebService的名称从Service1更改为Jobs ..我尝试执行此操作,但是随后在添加WebReference时却给出了Exception。

  2. Here in this webservice I am using Method Overloading but aginb while Adding WebReference its throwing the Exception and suggets using Message Attribute which I am not able to understand. 在此Web服务中,我在使用方法重载,但是在添加WebReference时却使用了aginb,它使用我无法理解的Message Attribute抛出了异常和提示。

  3. After Resolving the above two bugs as per your Suggestion..I am having problem with the return type. 根据您的建议解决了上述两个错误之后。返回类型我有问题。 I am using XMLDocument as the return type of all the WEBMethods but after adding it as web reference to the Client the Return Type of The Methods get changed to XMLNode how can I resolve this 我使用XMLDocument作为所有WEBMethods的返回类型,但是将其添加为对客户端的Web引用之后,方法的返回类型更改为XMLNode如何解决此问题

Waiting for Response guys.. 等待响应的家伙..

1: If you change the class name, you must also change the .asmx (or .svc for WCF) page, which has a (text) marker to Service1 . 1:如果更改类名,则还必须更改.asmx(对于WCF为.svc)页面,该页面的(文本)标记为Service1 Right-click the asmx and "View markup" - it should look something like: 右键单击asmx和“查看标记”-它应类似于:

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

Change the Class and CodeBehind to match your current setup. 更改ClassCodeBehind以匹配您当前的设置。

2: ws 1-1 doesn't support overloading. 2:ws 1-1不支持重载。 You simply need to add an attribute to give a unique name to each method on the SOAP interface. 您只需要添加一个属性即可为SOAP接口上的每个方法赋予唯一的名称。 However, note that this becomes the method name that your proxies will see. 但是,请注意,这成为代理将看到的方法名称。

For example, you might change one of the messages as below: 例如,您可以更改以下消息之一:

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

Now update the client; 现在更新客户端; you (if you use wsdl.exe etc) will probably have an InsertXml(...) method. 您(如果使用InsertXml(...)等)可能会有一个InsertXml(...)方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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