好的,所以我正在尝试将一个压缩文件发送到ebay LMS api,但对于像我这样的新手来说,这些东西的记录非常糟糕。
这是我得到的例外:
System.InvalidOperationException: Could not find endpoint element with name 'FileTransferServiceSOAP' and contract 'FileTransferServicePort' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
at System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory()
at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
at System.ServiceModel.ClientBase`1..ctor(String endpointConfigurationName)
at FileTransferServicePortClient..ctor(String endpointConfigurationName)
at Nop.Plugin.Widgets.DbgEnhancements.Services.EbayWebService.UploadFile(String jobID, String fileRefId, String fileName, String SecurityToken)
at Nop.Plugin.Widgets.DbgEnhancements.Services.EbayWebService.SendEbayBulkLMSRequest(String filePathZip)
这是我的ebaywebservice的代码:
public virtual void SendEbayBulkLMSRequest(string filePathZip)
{
var ebayAuthTokenSetting = _settingService.GetSettingByKey(
"ebaysetting.authtoken", "");
try
{
//Get the parameters from the app.config file
string jobID = "123";
string fileRefID = "123";
string fileName = filePathZip;
string SecurityToken = ebayAuthTokenSetting;
// Upload file
UploadFileResponse uploadResponse = UploadFile(jobID, fileRefID, fileName, SecurityToken);
// display response details
displayResponse(uploadResponse, fileName);
Debug.WriteLine("uploadResponse");
}
catch (Exception e)
{
Debug.WriteLine("\n An exception occured: \n\n" + e + "\n");
}
}
它说明了应用设置,但我不明白为什么我不能在nopcommerce的后端存储设置。
以下是我用于文件上传的其他方法:
//Call uploadFile
public static UploadFileResponse UploadFile(string jobID, string fileRefId, string fileName, string SecurityToken)
{
FileTransferServicePortClient client = new FileTransferServicePortClient("FileTransferServiceSOAP");
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
HttpRequestMessageProperty httpRequest = new HttpRequestMessageProperty();
OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest);
//Set HTTP headers
setHeaders(httpRequest, SecurityToken);
//Create upload file request
UploadFileRequest uploadReq = new UploadFileRequest();
uploadReq.fileAttachment = getFileAttachment(fileName);
uploadReq.fileReferenceId = fileRefId;
uploadReq.taskReferenceId = jobID;
uploadReq.fileFormat = "gzip";
//Make the uploadFile call and return the response
UploadFileResponse uploadResponse = client.uploadFile(uploadReq);
return uploadResponse;
}
}
//Sets HTTP headers for the request
public static HttpRequestMessageProperty setHeaders(HttpRequestMessageProperty httpRequest, string SecurityToken)
{
//Add the request headers
httpRequest.Headers.Add("X-EBAY-SOA-SECURITY-TOKEN", SecurityToken);
httpRequest.Headers.Add("X-EBAY-SOA-SERVICE-NAME", "FileTransferService");
httpRequest.Headers.Add("X-EBAY-SOA-SERVICE-VERSION", "1.0.0");
httpRequest.Headers.Add("X-EBAY-SOA-REQUEST-DATA-FORMAT", "XML");
httpRequest.Headers.Add("X-EBAY-SOA-RESPONSE-DATA-FORMAT", "XML");
httpRequest.Headers.Add("X-EBAY-SOA-MESSAGE-PROTOCOL", "SOAP12");
httpRequest.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "uploadFile");
return httpRequest;
}
//Reads the file from the location specified
public static FileAttachment getFileAttachment(String fileName)
{
FileAttachment attachment = new FileAttachment();
FileStream fs = File.OpenRead(fileName);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
attachment.Data = data;
attachment.SizeSpecified = true;
attachment.Size = fs.Length;
return attachment;
}
//Displays the result of the uploadFile call
public static void displayResponse(UploadFileResponse uploadResponse, string fileName)
{
string txt = "";
switch (uploadResponse.ack)
{
case AckValue.Success:
Debug.WriteLine("uploadFile Status: Success");
Debug.WriteLine(uploadResponse.timestamp);
txt += fileName + " was successfully uploaded to the server.\n\n";
Debug.WriteLine(txt);
break;
case AckValue.Failure:
Debug.WriteLine(uploadResponse.timestamp);
Debug.WriteLine("uploadFile Status: Failure");
break;
case AckValue.Warning:
Debug.WriteLine(uploadResponse.timestamp);
Debug.WriteLine("uploadFile Status: Warning");
break;
case AckValue.PartialFailure:
Debug.WriteLine(uploadResponse.timestamp);
Debug.WriteLine("uploadFile Status: PartialFailure");
break;
}
// display error messages received if any
if (uploadResponse.errorMessage != null)
{
foreach (ErrorData error in uploadResponse.errorMessage)
{
Debug.WriteLine(error.message);
}
}
}
我正在工作from this page如果您查看文件附件,我会在nopcommerce中使用FTSSample.zip作为服务。
任何人都知道我哪里出错,欢呼。