简体   繁体   English

如何从asmx Web服务查看我的类

[英]How to view my classes from asmx web service

I have one ASMX webservice with C#. 我有一个带有C#的ASMX Web服务。 In this WebService I use some classes with properties. 在这个WebService中,我使用了一些带有属性的类。 The Class is in the same namespace as Service1.asmx. Class与Service1.asmx位于同一名称空间中。

Code of my Web Service: 我的Web服务代码:

namespace NewWebService
{
    [WebService(Namespace = "http://www.MySite.net/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {     
        [WebMethod]
        public string GetUsers(string authenticatedToken) //out string error
        {

            //Extract from database the users...

            return Serialize(usersList);
        }
    ...
    }
}

Code of my class: 我班的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NewWebService
{
    public class Users
    {
        public int ID { get; set; }
        public string Name { get; set; }
        ...
    }
}

The question is: what must I make with my class to can view it in project where I added the webservice. 问题是:我必须在课程中查看我可以在添加了webservice的项目中查看它。

You're returning a string : 你要返回一个string

public string GetUsers(string authenticatedToken)

So the public definition for the web service is only going to expose information about a string . 因此,Web服务的公共定义仅用于公开有关string信息。 There's nothing in the public interface regarding your class, so the web service doesn't advertise any information about your class. 公共界面中没有关于您的课程的内容,因此Web服务不会宣传您的课程的任何信息。

Return a strongly-typed instance of the class. 返回类的强类型实例。 Something like this: 像这样的东西:

public IEnumerable<User> GetUsers(string authenticatedToken)

Then the generated web service code will include a definition of the type being returned, so consuming clients will be able to understand that type. 然后生成的Web服务代码将包含要返回的类型的定义,因此使用客户端将能够理解该类型。 (And, for example, generate a local analog of that type if the consuming client includes code-generating capabilities. It wouldn't be the same type from an assembly perspective, but across a service boundary that shouldn't really be a concern.) (例如,如果消费客户端包含代码生成功能,则生成该类型的本地模拟。从汇编角度来看,它不是相同的类型,而是跨越服务边界,这不应该是一个真正关注的问题。 )

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

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