我在empdeatails类上创建该类,其中包含所有详细信息,而empDA包含与SQL Server的数据交互。我创建一个授权类,即user是soapheader和checkuser类,在其中我声明方法checkuser1(user u)用来检查用户是否是授权用户。
我创建一个soapservice,即userdetails类,在其中创建insertemp(empdeatails e),并且在运行thorw错误时“提交按钮上的asp.net表单中使用了该服务”“方法'insertemp'的无重载需要1个参数” 。如何解决这个问题。
我在同一项目中创建了我的肥皂服务。我只是按照我们添加服务引用的步骤添加引用。然后,我简单地创建empdetails传递数据的对象,然后调用我的服务方法并在其中传递empdetails对象,但是它们的显示编译错误,即“方法'insertemp'的重载不接受1个参数”。
Addemp.cs
const request = require('request');
const storage = require('azure-storage');
var accountName = '<your storage account name>';
var accountKey = '<your storage account name>';
var blobService = storage.createBlobService(accountName, accountKey);
let stream = blobService.createReadStream(containerName, blobName, function(err, res){
formdata.file.options.contentType = res.contentSettings.contentType;
console.log(formdata);
});
var formdata = {
rootMessageId: messageId,
file: { // missing some properties
value: stream,
options: {
filename: function(blobName) {
var elems = blobName.split('/');
return elems[elems.length-1];
}(blobName),
knownLength: stream // a required property of `file` is `knownLength` which will cause server error if be missed.
},
}
}
request.post({
url: 'https://host-name/Api/comment', // I used my url `http://localhost/upload` at here
headers: {'Authorization': `Token ${authToken}`}, // I used a empty {} as header at here
formData: formdata
}, (err, res, body) => {
console.log(res)
}
});
userdetails.asmx => userdetails.cs
public partial class Emp_Addemp
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsub_Click(object sender, EventArgs e)
{
user u = new user();
u.username = "chek";
u.password = "testpass";
ServiceReference1.empdetails e1 = new ServiceReference1.empdetails();
//userdetails u = new userdetails();
ServiceReference1.userdetailsSoapClient client = new ServiceReference1.userdetailsSoapClient("userdetailsSoap");
string gen ="";
if (rdbmale.Checked)
{
gen = "Male";
}
else
{
gen = "Female";
}
e1.eid = -1;
e1.ename = txtname.Text;
e1.eaddress = txtadd.Text;
e1.emobileno = txtmobileno.Text;
e1.gender = gen;
e1.ejoiningdate = DateTime.Now;
e1.eleavedate = DateTime.Now;
e1.status = true;
int emid = client.insertemp(e1); //Error
}
}
empdeatails.cs =>简单声明变量
empDA.cs =>数据连接代码
[WebService(Namespace = "http://localhost:35046/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class userdetails : System.Web.Services.WebService {
public userdetails () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
public user checkuser;
//[SoapHeader("checkuser", Required = true)]
[WebMethod]
public int insertemp(empdetails emp)
{
int eid = 0;
eid = empDA.insertuserdetails(emp);
return eid;
}
}