I am trying to pass an array of a simple object to a web service and I'm really stuck on this error during compile of my web client project:
Cannot implicitly convert type 'TRIMBrokerUtil.MetaData[]' to 'TRIMBrokerASMXProxy.ASMXProxy.MetaData[]'
Here is my "utility" project compiled into 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)
{
...and usage later as this:
Update update = BuildMetaData(metaDataArray);
...and this:
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;
}
Next, (via "Add Web Reference") I have my proxy class for the ASMX webservice in a separate project and it compiles without problem. Inside the generated reference.cs file I find this which seems OK:
[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]));
}
Now for the error that occurs in compilation in the web client project (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 );
I have also tried changing the last 2 lines above to simply this one line:
strURI = client.UploadFile(binData, fileNameOnly, binData.Length, metaDataArray);
...but that change introduces a 2nd error from the compiler which reads as:
The best overloaded method match for 'TRIMBrokerASMXProxy.ASMXProxy.FileService.UploadFile(byte[], string, long, TRIMBrokerASMXProxy.ASMXProxy.MetaData[])' has some invalid arguments
(note the original error about "cannot convert" is the 2nd error).
Sorry about being so verbose above. Hope you can help shed light on this confusion.