我正在尝试将一个简单对象的数组传递给一个Web服务,但是在编译我的Web客户端项目时,我真的卡在了这个错误上:
无法隐式转换类型 TRIMBrokerUtil.MetaData[] 到 TRIMBrokerASMXProxy.ASMXProxy.MetaData[]。
这是我编译为TRIMBrokerUtil.dll的“实用性”项目:
namespace TRIMBrokerUtil
{
public class MetaData
{
protected string _Name;
protected string _Value;
public MetaData(string keyword, string setting)
{
this.Name = keyword;
this.Value = setting;
}
public string Name
{
get
{
return this._Name;
}
set
{
Name = value;
}
}
public string Value
{
get
{
return this._Value;
}
set
{
_Value = value;
}
}
}
Here is a snippet of the web service which also compiles fine: using TRIMBrokerUtil; namespace TRIMBrokerService { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class FileService : System.Web.Services.WebService {
[WebMethod]
public string UploadFile(byte[] incomingArray
, string FileName
, long FileLengthInBytes
, MetaData[] metaDataArray)
{
将来的使用如下:
Update update = BuildMetaData(metaDataArray);
Sorry, there is no context or text provided for me to translate. Please provide me with the text you wish to be translated into Chinese.
private Update BuildMetaData(MetaData[] nvPairs)
{
Update update = new Update();
InputProperty[] ip = new InputProperty[nvPairs.Length];
int i;
for (i=0; i < nvPairs.Length; i++)
{
ip[i].Name = "udf:" + nvPairs[i].Name;
ip[i].Val = nvPairs[i].Value;
}
update.Items = ip;
return update;
}
接下来,(通过“添加Web引用”),我在一个单独的项目中拥有用于ASMX webservice的代理类,它编译没有问题。在生成的reference.cs文件中,我发现这个看起来没问题:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/UploadFile", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string UploadFile([System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] incomingArray, string FileName, long FileLengthInBytes, MetaData[] metaDataArray) {
object[] results = this.Invoke("UploadFile", new object[] {
incomingArray,
FileName,
FileLengthInBytes,
metaDataArray});
return ((string)(results[0]));
}
现在谈论网页客户端项目中编译时出现的错误(default.aspx.cs)。
using TRIMBrokerUtil;
public partial class _Default : System.Web.UI.Page
{
private void UploadFile(HttpPostedFile postedFile
, string fileNameOnly
, MetaData[] metaDataArray)
{
string strURI = string.Empty;
TRIMBrokerASMXProxy.ASMXProxy.FileService client = new TRIMBrokerASMXProxy.ASMXProxy.FileService();
BinaryReader b = new BinaryReader(postedFile.InputStream);
byte[] binData = b.ReadBytes(numBytes);
TRIMBrokerASMXProxy.ASMXProxy.MetaData[] kvData = metaDataArray; // error complains about this line
strURI = client.UploadFile(binData, fileNameOnly, binData.Length, kvData );
我还尝试着将上述最后两行改变成简单的一行:
strURI = client.UploadFile(binData, fileNameOnly, binData.Length, metaDataArray);
但是这个改变引入了第二个编译器错误,读作:
TRIMBrokerASMXProxy.ASMXProxy.FileService.UploadFile(byte[], string, long, TRIMBrokerASMXProxy.ASMXProxy.MetaData[]) 的最佳重载方法匹配存在一些无效参数。
请将以下内容翻译成中文:(请注意“不能转换”的原始错误为第二个错误)。
对我之前的冗长感到抱歉。希望你能帮助澄清这个困惑。