简单的网络服务问题 [英] Simple web service Question

查看:75
本文介绍了简单的网络服务问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为学校的一个班级编写一个简单的Web服务.我已经写好了它并且可以正常工作,但是我无法按照指令指示的方式(下面)来显示(这就是它要做的全部).任何建议,将不胜感激.我是新手.

 <  顺序 > ; 
<  购物者名称 >  Sam Spade <  /shoppername  > 
<  购物者地址 >  101 Main St <  /shopperaddress  > 
<  项目 > 
<  项目 > 
<  名称 >  T恤<  /name  > 
<   sku  >  T001 <  /sku  > 
<  成本 >  7.00 <  /cost  > 
<  选项 > 
<  颜色 > 绿色<  /color  > 
<  大小 >  S <  /size  > 
<  /Options  > 
<  /item  > 
<  项目 > 
<  名称 > 裤子<  /name  > 
<   sku  >  P002 <  /sku  > 
<  成本 >  17.00 <  /cost  > 
<   Options/ > 
<  /item  > 
<  /items  > 
<   orderid  >  1 <  /orderid  > 
<  /order  >  


我有这个,它很接近,但是缺少一些东西,并且结构不一样:

-<   arrayoforder     xmlns   ="   xmlns:xsd       xmlns:xsi   ="  <  订单 > 
<  购物者名称 >  Sam Spade <  /shoppername  > 
<  购物者地址 >  101大街<  /shopperaddress  > 
-<  项目 > 
<  名称 >  T恤<  /name  > 
<   sku  >  T001 <  /sku  > 
<  成本 >  7 <  /cost  > 
-<  选项 > 
<  颜色 > 绿色<  /color  > 
<  大小 >  S <  /size  > 
<  /options  > 
<  /item  > 
<  /order  > 
-<  订单 > 
-<  项目 > 
<  名称 > 裤子<  /name  > 
<   sku  >  P002 <  /sku  > 
<  成本 >  17 <  /cost  > 
<   options/ > 
<  /item  > 
<  /order  > 
<  /arrayoforder  >  



当前代码:

  public   struct 顺序
        {
            公共 字符串 ShopperName;
            公共 字符串 ShopperAddress;
            
             public 项项;
        }
        公共 结构
        {
            公共 字符串名称;
            公共 字符串 sku;
            公共 两倍费用;
             public 选项选项;
        }
        公共 结构选项
        {
            公共 字符串颜色;
            公共 字符串大小;
        }

        [WebMethod]
        公共 Order [] GetOrder( int  OrderID)
        {
          
            Order [] newOrder =  Order [ 2 ];

            newOrder [ 0 ] =  new  Order();

            newOrder [ 0 ].ShopperName = " ;
            newOrder [ 0 ].ShopperAddress = " ;
           
            newOrder [ 0 ].Item.name = " ;
            newOrder [ 0 ].Item.sku = " ;
            newOrder [ 0 ].Item.cost =  7 . 00 ;
            newOrder [ 0 ].Item.options.color = " ;
            newOrder [ 0 ].Item.options.size = " ;

            newOrder [ 1 ] =  new  Order();

            newOrder [ 1 ].Item.name = " ;
            newOrder [ 1 ].Item.sku = " ;
            newOrder [ 1 ].Item.cost =  17 . 00 ;
            newOrder [ 1 ].Item.options.ToString();

            返回 newOrder;

        }
    }
} 

解决方案

首先,您可以将数据合同Orders,Items设置为Serializable.

其次,您可以通过wcftestclient测试Web服务,以捕获使用Web服务方法GetOrder的确切异常.现在都固定了.感谢您的所有/所有输入.


I am trying to write a simple web service for a class in school. I have it written and it works, but I cannot get it to display (That is all it has to do) the way the instructions dictate (below). Any suggestions would be appreciated. I am a novice.

<order>
	<shoppername>Sam Spade</shoppername>
	<shopperaddress>101 Main St</shopperaddress>
	<items>
		<item>
			<name>T-Shirt</name>
			<sku>T001</sku>
			<cost>7.00</cost>
			<Options>
				<color>green</color>
				<size>S</size>
			</Options>
		</item>
		<item>
			<name>Pants</name>
			<sku>P002</sku>
			<cost>17.00</cost>
			<Options/>
		</item>
	</items>
	<orderid>1</orderid>
</order>


I have this, which is close but missing a few things and doesn''t have the same structure:

-<arrayoforder xmlns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
	-<order> 
		<shoppername>Sam Spade</shoppername> 
		<shopperaddress>101 Main Street</shopperaddress> 
		-<item> 
			<name>T-Shirt</name> 
			<sku>T001</sku> 
			<cost>7</cost> 
			-<options> 
				<color>green</color> 
				<size>S</size> 
			</options> 
		</item>
	</order> 
	-<order> 
		-<item> 
			<name>Pants</name> 
			<sku>P002</sku> 
			<cost>17</cost> 
			<options/> 
		</item> 
	</order> 
</arrayoforder>



Current code:

        public struct Order
        {
            public string ShopperName;
            public string ShopperAddress;
            
            public Items Item;
        }
        public struct Items
        {
            public string name;
            public string sku;
            public double cost;
            public Options options;
        }
        public struct Options
        {
            public string color;
            public string size;
        }

        [WebMethod]
        public Order[] GetOrder(int OrderID)
        {
          
            Order[] newOrder = new Order[2];

            newOrder[0] = new Order();

            newOrder[0].ShopperName = "Sam Spade";
            newOrder[0].ShopperAddress = "101 Main Street";            
           
            newOrder[0].Item.name = "T-Shirt";
            newOrder[0].Item.sku = "T001";
            newOrder[0].Item.cost = 7.00;
            newOrder[0].Item.options.color = "green";
            newOrder[0].Item.options.size = "S";

            newOrder[1] = new Order();

            newOrder[1].Item.name = "Pants";
            newOrder[1].Item.sku = "P002";
            newOrder[1].Item.cost = 17.00;
            newOrder[1].Item.options.ToString();

            return newOrder;

        }
    } 
}

解决方案

First thing, you can make the data contracts Orders, Items as Serializable.

Second, you can test the webservice via wcftestclient to catch the exact exception on consuming web service method GetOrder


I had the structures defined incorrectly and was not calling the arrays properly. All fixed now. Thanks for any/all input.


这篇关于简单的网络服务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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