如何为Web服务声明复杂的嵌套C#类型 [英] How to Declare Complex Nested C# Type for Web Service

查看:127
本文介绍了如何为Web服务声明复杂的嵌套C#类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个接受复杂嵌套类型的服务.在一个示例asmx文件中,我创建了:

I would like to create a service that accepts a complex nested type. In a sample asmx file I created:


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 ServiceNest : System.Web.Services.WebService
{
   public class Block
   {
      [XmlElement(IsNullable = false)]
      public int number;
   }

   public class Cell
   {
      [XmlElement(IsNullable = false)]
      public Block block;
   }

   public class Head
   {
      [XmlElement(IsNullable = false)]
      public Cell cell;
   }

   public class Nest
   {
      public Head head;
   }

   [WebMethod]
   public void TakeNest(Nest nest)
   {
   }

}

当我在IE中查看asmx文件时,测试页将示例SOAP发布请求显示为:

When I view the asmx file in IE the test page shows the example SOAP post request as:


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <TakeNest xmlns="http://schemas.intellicorp.com/livecompare/">
      <nest>
        <head>
          <cell>
            <block xsi:nil="true" />
          </cell>
        </head>
      </nest>
    </TakeNest>
  </soap:Body>
</soap:Envelope>

它没有扩展< block>成为其数字会员.

It hasn't expanded the <block> into its number member.

看看WSDL,所有类型看起来都很不错.那么这仅仅是演示页面创建者的限制吗?

Looking at the WSDL, the types all look good. So is this just a limitation of the post demo page creator?

谢谢.

推荐答案

但那些元素 ARE 为空.您需要先构建它们,然后它们才会显示为空.

But those elements ARE null. You need to construct them before they show up otherwise they are just null.

这篇关于如何为Web服务声明复杂的嵌套C#类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆