读书人

[]帮小弟我看看这个webservice吧如何

发布时间: 2012-01-20 18:53:53 作者: rapoo

[求助]帮我看看这个webservice吧,怎么样接收和返回对象数组?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using MySQLDriverCS;
using MySQLConn;
using XpsPublicInfo;
namespace APService
{
/// <summary>
/// NewProductOrder 的摘要说明。
/// </summary>
[WebService(Namespace= "http://www.openuri.org/ ")]
public class NewProductOrder : System.Web.Services.WebService
{
public NewProductOrder()
{
//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();
}

#region 组件设计器生成的代码

//Web 服务设计器所必需的
private IContainer components = null;

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{


components.Dispose();
}
base.Dispose(disposing);
}

#endregion


[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( "http://www.openuri.org/order ", RequestNamespace= "http://www.openuri.org/ ", ResponseNamespace= "http://www.openuri.org/ ", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

public OrderResponseType order(OrderRequestType request)
{

// int n=request.productInfo.GetLength(1);
// string[] requestinfo=new string[2];
// string[] responseinfo=new string[2];
// ProductPropertiesType[] requestInfo=request.productInfo;
// for(int i=0;i <n;i++)
// {
// ProductPropertiesType type= requestInfo[i];
// requestinfo[0]=type.fieldName;
// requestinfo[1]=type.fieldValue;
// }

string myhashCode=publicInfo.md5(request.bnetID+request.bnetAccount+request.productSpecID+request.customerName+request.timestamp+ "123 ");


string err= "定购接口测试 ";
int result;
OrderResponseType order = new OrderResponseType();

if(publicInfo.checkpara(request.bnetID,1,11)&&publicInfo.checkpara(request.bnetAccount,1,30)&&publicInfo.checkpara(request.productSpecID,1,10)&&publicInfo.checkpara(request.customerName,1,80)&&publicInfo.checkpara(request.hashCode,1,32)&&publicInfo.checkpara(request.timestamp,1,18))
{

if(request.hashCode==myhashCode)
{
MySQLDataReader dr=conn.datareader( "select bnetID from bnetInfo where bnetID= "+request.bnetID);
if(!dr.Read())
{
try
{
conn.execsql( "insert into bnetInfo(bnetID,bnetAccount,productSpecID,customerName,nums) values( ' "+request.bnetID+ " ', ' "+request.bnetAccount+ " ', 'SC9900053 ', ' "+request.customerName+ " ',3) ");
result=0;
}


catch(Exception ee)
{
err=ee.ToString();
result=-1;

}
finally
{
order.info=err;
}
}
else
{
result=-1;


}
}
else
{
result=-3;
}
}
else
{
result=-2;
}
order.bnetID=request.bnetID;
order.result=result;
order.info=err;
//order.productInfo.SetValue(0)=request.productInfo.GetValue(0);
//order.productInfo.SetValue(1)=request.productInfo.GetValue(1);
order.hashCode=myhashCode;
order.timestamp= "888888888822222222 ";
return order;
}
}

public class OrderResponseType
{
public string bnetID;

public int result;


public string info;

[System.Xml.Serialization.XmlArrayItemAttribute( "property ", IsNullable=false)]
public ProductPropertiesType[] productInfo;

public string hashCode;

public string timestamp;
}

public class ProductPropertiesType
{


public string fieldName;

public string fieldValue;
}

public class OrderRequestType
{

public string bnetID;

public string bnetAccount;

public string productSpecID;

public string customerName;

[System.Xml.Serialization.XmlArrayItemAttribute( "property ", IsNullable=false)]
public ProductPropertiesType[] productInfo;

public string hashCode;

public string timestamp;
}
}


代码编译成功但在xmlspy中老是返回 the web service has sent and empty response


[解决办法]
up
[解决办法]
没看懂,顶一下.

[解决办法]
[WebMethod]
public string test (class1[] model)
{
for (int r = 0; r < model.Length; r++)
{
model[r] //即是每个对象
}
}

//客户端
class1[] arrClass=new class1[10];//Define an array
//Init members
for(int i=0;i <10;i++)
arrClass[i]=new class1();

读书人网 >C#

热点推荐