【问题标题】:Extra clases in asmx soap webserviceasmx 肥皂网络服务中的额外类
【发布时间】:2019-12-23 11:46:44
【问题描述】:

我已经使用 c# 制作了自己的 asmx 网络服务。我的主课是这样的

[WebService(Namespace = "my.namespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[SoapDocumentService(SoapBindingUse.Literal, SoapParameterStyle.Bare, RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public class ICService : System.Web.Services.WebService
{
    [WebMethod()]
    public ProductListResponse GetProductList(ProductListRequest ProductListRequest) { ... }

}

如果我在网络上查看此方法的 xml 请求,结果如下:

<soap:Body>
  <ProductListRequest xmlns="my.namespace">
    . . .
  </ProductListRequest>
</soap:Body>

一切都很好,但是当我在任何其他项目中添加对此 WS 的引用时,我需要额外的方法调用类。不是什么大问题,但我想知道为什么会这样。

调用示例:

GetProductListResponse resp = client.GetProductList(new GetProductListRequest
{
    ProductListRequest = new ProductListRequest { }
});

这个 GetProductListRequest 类从何而来? Anwser 似乎有额外的类:GetProductListResponse.GetProductListResult.Products 而不仅仅是 ProductListResponse.Products。

我使用过许多其他网络服务,但这种行为对我来说是新的。

【问题讨论】:

    标签: c# .net web-services soap asmx


    【解决方案1】:

    当您添加对 SOAP Web 服务的引用时,Visual Studio 可以生成消息协定。它是一个将包装所有方法参数的类。在更新服务并添加新参数时很有用。

    如果您不想要这些消息合同,您可以在添加参考时在高级设置中取消选中它。您也可以通过右键单击服务参考然后选择配置服务参考来访问此表单。

    您也可以使用[MessageContract] 属性装饰ProductListRequest,Visual Studio 将使用此类型而不是创建新类型

    您可以在官方文档中找到有关消息合约的更多信息:Using Message Contracts

    【讨论】:

    • 我试过检查,但结果是一样的。关于 [MessageContract],我需要任何 dll 吗?没找到
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2017-01-16
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多