读取操作
var instance = new WebReference.service1();
instance.Credentials = new NetworkCredential(“K8NY4FCZOQP”, “Aaaaaaa5”);
//var instance = new Y3YCI6DOY_WSserviceClient(“binding1”);
//serviceInstance.c
//instance.ClientCredentials.UserName.UserName = “K8NY4FCZOQP”;
//instance.ClientCredentials.UserName.Password = “Aaaaaaa5”;
AddMultReadByIDQuery addmult = new AddMultReadByIDQuery();
addmult.OperationID = this.TextBox5.Text;
AddMultReadByIDQueryMessage_sync ReadBy = new AddMultReadByIDQueryMessage_sync();
ReadBy.AddMult = addmult;
AddMultReadByIDResponseMessage_sync readResponse = new AddMultReadByIDResponseMessage_sync();
readResponse = instance.Read(ReadBy);
AddMultReadByIDResponse ReadByID = new AddMultReadByIDResponse();
ReadByID = readResponse.AddMult;
this.TextBox1.Text = ReadByID.Value1.ToString();
this.TextBox2.Text = ReadByID.Value2.ToString();
this.TextBox3.Text = ReadByID.Result1.ToString();
this.TextBox4.Text = ReadByID.Result2.ToString();
创建
var instance = new WebReference.service1();
instance.Credentials = new NetworkCredential(“K8NY4FCZOQP”, “Aaaaaaa5”);
//var instance = new Y3YCI6DOY_WSserviceClient(“binding1”);
//serviceInstance.c
//instance.ClientCredentials.UserName.UserName = “K8NY4FCZOQP”;
//instance.ClientCredentials.UserName.Password = “Aaaaaaa5”;
AddMultCreateRequest create = new AddMultCreateRequest();
create.Value1Specified = true;
create.Value1 = Convert.ToInt32(this.TextBox1.Text);
create.Value2Specified = true;
create.Value2 =Convert.ToInt32(this.TextBox2.Text);
create.OperationID = this.TextBox5.Text;
AddMultCreateRequestMessage_sync createRequest=new AddMultCreateRequestMessage_sync ();
createRequest.AddMult=create;
AddMultCreateConfirmationMessage_sync creteConfir = instance.Create(createRequest);
if (creteConfir!=null)
{
if (creteConfir.AddMult.OperationID!=””)
{
Response.Write(“<script>alert(‘添加成功’);</script>”);
}
}
这里主要的难题是那个验证:instance.Credentials = new NetworkCredential(“K8NY4FCZOQP”, “Aaaaaaa5”);
我试过很多方法,以后可能也会继续研究。不过现在开发需要,只能点到即止了!
在这里我学到了两种方法引用web服务。说是两种其实是一种,因为第二种是在第一种无法实现的情况下(不兼容的情况下)才用。
第一种:
第二种:点击高级→点击引用web服务
其实两种的所填的路径都一样,只是第一种有更严格的验证和保密机制,第二种就相对弱点,都是明文传送容易被截取。
仔细研究.net 根据wsdl自动生成的类,就会发现。有一定的规律在里面。比如:
AddMultReadByIDQueryMessage_sync 查找的类参数
AddMultReadByIDResponseMessage_sync 同步返回的类
AddMultCreateRequestMessage_sync 创建时的参数
AddMultCreateConfirmationMessage_sync 同步返回时的类
和普通的类调用相比,虽然可以看出会多出很多复杂和多余的类,但是还是有一些本来的重要属性在里面。
比如:创建时,需要必填的字段必须设置Value1Specified为true;
create.Value1Specified = true;
create.Value1 = Convert.ToInt32(this.TextBox1.Text);
create.Value2Specified = true;
create.Value2 =Convert.ToInt32(this.TextBox2.Text);
转载于:https://www.cnblogs.com/sanshisankuai/archive/2012/10/28/2743748.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110294.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...