如何在html表单汇总时调用wcf服务 [英] How to call wcf service when html form is sumbitted

查看:69
本文介绍了如何在html表单汇总时调用wcf服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,







<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">

< html xmlns =http:/ /www.w3.org/1999/xhtml\">

< head>

< title>< / title>

< / head>

< body>

< form action =http:// localhost:49251 / Service1.svc / AddDatamethod =post target =_ blank>

< label> FirstName< / label>

< input type =textsize =30name =FirstName />

< label> LastName< / label>

< input type =textsize =30name =LastName/> ;

< input type =submitvalue =Submit/>

< / form>

< / body> ;

< / html>





当我点击提交按钮时,它应该调用我的AddData ()wcf功能。怎么做?

如果可能的话给我web.config文件也有一些例子。



WCF:





公共函数AddData()As String Implements IService1.AddData

返回

结束函数

解决方案

您不应该将表单发布到Web服务,最好使用jquery和ajax调用:使用jQuery调用WCF服务 [ ^ ]。但如果你坚持下去,请看这里: http://stackoverflow.com/questions/1354749/wcf-service-to-accept-a-post-encoded-multipart-form-data#answer-1407139 [ ^ ]

HI,



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="http://localhost:49251/Service1.svc/AddData" method="post" target="_blank">
<label >FirstName</label>
<input type="text" size="30" name="FirstName" />
<label >LastName</label>
<input type="text" size="30" name="LastName" />
<input type="submit" value="Submit" />
</form>
</body>
</html>


When I click on Submit button,it should call my AddData() wcf function.How to do that?
If possible give me some examples with web.config file also.

WCF:


Public Function AddData() As String Implements IService1.AddData
Return ""
End Function

解决方案

You should not post a form to a web service, you better use jquery and an ajax call for that: Calling WCF Services using jQuery[^]. But if you stick to it, look here: http://stackoverflow.com/questions/1354749/wcf-service-to-accept-a-post-encoded-multipart-form-data#answer-1407139[^]


这篇关于如何在html表单汇总时调用wcf服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆