------------------------------------------------------------------------------
<auto-generated>
此代码由工具生成。
运行时版本:4.0.30319.225
//
对此文件的更改可能会导致不正确的行为,并且如果
重新生成代码,这些更改将会丢失。
</auto-generated>
------------------------------------------------------------------------------
//
此源代码由 wsdl 自动生成,Version=4.0.30319.1。
namespace Bingosoft.Module.SurveyQuestionnaire.DAL {
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System.Web.Services;
using System.Data;
<remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute(
wsdl4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(code")]
[System.Web.Services.WebServiceBindingAttribute(Name=
WebserviceForILookSoap")]
partial class WebserviceForILook : System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback GetRecordNumOperationCompleted;
private System.Threading.SendOrPostCallback GetVoteListOperationCompleted;
private System.Threading.SendOrPostCallback VoteOperationCompleted;
private System.Threading.SendOrPostCallback GiveUpOperationCompleted;
private System.Threading.SendOrPostCallback GetQuestionTaskListOperationCompleted;
<remarks/>
public WebserviceForILook() {
this.Url =
http://st1.services.gmcc.net/qnaire/Services/WebserviceForILook.asmx";
}
event GetRecordNumCompletedEventHandler GetRecordNumCompleted;
event GetVoteListCompletedEventHandler GetVoteListCompleted;
event VoteCompletedEventHandler VoteCompleted;
event GiveUpCompletedEventHandler GiveUpCompleted;
event GetQuestionTaskListCompletedEventHandler GetQuestionTaskListCompleted;
<remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(
http://tempuri.org/GetRecordNumSystem.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
int[] GetRecordNum(
string appcode,255); line-height:1.5!important">string
userID) {
object[] results =
this.Invoke(
GetRecordNumnew object[] {
appcode,userID});
return ((
int[])(results[
0]));
}
public System.IAsyncResult BeginGetRecordNum(
string userID,System.AsyncCallback callback,255); line-height:1.5!important">object
asyncState) {
return this.BeginInvoke(
int[] EndGetRecordNum(System.IAsyncResult asyncResult) {
this.EndInvoke(asyncResult);
void GetRecordNumAsync(
this.GetRecordNumAsync(appcode,userID,255); line-height:1.5!important">null
);
}
object userState) {
if ((
this.GetRecordNumOperationCompleted ==
null)) {
this.GetRecordNumOperationCompleted =
new System.Threading.SendOrPostCallback(
this.OnGetRecordNumOperationCompleted);
}
this.InvokeAsync(
this.GetRecordNumOperationCompleted,userState);
}
private void OnGetRecordNumOperationCompleted(
object arg) {
this.GetRecordNumCompleted !=
null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs =
((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetRecordNumCompleted(
this,255); line-height:1.5!important">new
GetRecordNumCompletedEventArgs(invokeArgs.Results,invokeArgs.Error,invokeArgs.Cancelled,invokeArgs.UserState));
}
}
http://tempuri.org/GetVoteListpublic System.Data.DataSet GetVoteList(
GetVoteListreturn ((System.Data.DataSet)(results[
public System.IAsyncResult BeginGetVoteList(
public System.Data.DataSet EndGetVoteList(System.IAsyncResult asyncResult) {
void GetVoteListAsync(
this.GetVoteListAsync(appcode,255); line-height:1.5!important">this.GetVoteListOperationCompleted ==
this.GetVoteListOperationCompleted =
this.OnGetVoteListOperationCompleted);
}
this.GetVoteListOperationCompleted,255); line-height:1.5!important">void OnGetVoteListOperationCompleted(
this.GetVoteListCompleted !=
this.GetVoteListCompleted(
new GetVoteListCompletedEventArgs(invokeArgs.Results,0); line-height:1.5!important">http://tempuri.org/Votebool Vote(
string qTaskID,255); line-height:1.5!important">string
answer) {
Votebool)(results[
public System.IAsyncResult BeginVote(
string answer,answer},255); line-height:1.5!important">bool
EndVote(System.IAsyncResult asyncResult) {
void VoteAsync(
this.VoteAsync(appcode,answer,255); line-height:1.5!important">this.VoteOperationCompleted ==
this.VoteOperationCompleted =
this.OnVoteOperationCompleted);
}
this.VoteOperationCompleted,255); line-height:1.5!important">void OnVoteOperationCompleted(
this.VoteCompleted !=
this.VoteCompleted(
new VoteCompletedEventArgs(invokeArgs.Results,0); line-height:1.5!important">http://tempuri.org/GiveUpbool GiveUp(
string qTaskID) {
GiveUppublic System.IAsyncResult BeginGiveUp(
bool EndGiveUp(System.IAsyncResult asyncResult) {
void GiveUpAsync(
this.GiveUpAsync(appcode,255); line-height:1.5!important">this.GiveUpOperationCompleted ==
this.GiveUpOperationCompleted =
this.OnGiveUpOperationCompleted);
}
this.GiveUpOperationCompleted,255); line-height:1.5!important">void OnGiveUpOperationCompleted(
this.GiveUpCompleted !=
this.GiveUpCompleted(
new GiveUpCompletedEventArgs(invokeArgs.Results,0); line-height:1.5!important">http://tempuri.org/GetQuestionTaskListpublic System.Data.DataSet GetQuestionTaskList(
GetQuestionTaskListpublic System.IAsyncResult BeginGetQuestionTaskList(
public System.Data.DataSet EndGetQuestionTaskList(System.IAsyncResult asyncResult) {
void GetQuestionTaskListAsync(
this.GetQuestionTaskListAsync(appcode,255); line-height:1.5!important">this.GetQuestionTaskListOperationCompleted ==
this.GetQuestionTaskListOperationCompleted =
this.OnGetQuestionTaskListOperationCompleted);
}
this.GetQuestionTaskListOperationCompleted,255); line-height:1.5!important">void OnGetQuestionTaskListOperationCompleted(
this.GetQuestionTaskListCompleted !=
this.GetQuestionTaskListCompleted(
new GetQuestionTaskListCompletedEventArgs(invokeArgs.Results,255); line-height:1.5!important">void CancelAsync(
base.CancelAsync(userState);
}
}
delegate void GetRecordNumCompletedEventHandler(
object sender,GetRecordNumCompletedEventArgs e);
class GetRecordNumCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
object[] results;
internal GetRecordNumCompletedEventArgs(
object[] results,System.Exception exception,255); line-height:1.5!important">bool cancelled,255); line-height:1.5!important">object
userState) :
base(exception,cancelled,userState) {
this.results =
results;
}
int[] Result {
get {
this.RaiseExceptionIfNecessary();
int[])(
this.results[
0]));
}
}
}
void GetVoteListCompletedEventHandler(
class GetVoteListCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
internal GetVoteListCompletedEventArgs(
public System.Data.DataSet Result {
return ((System.Data.DataSet)(
void VoteCompletedEventHandler(
class VoteCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
internal VoteCompletedEventArgs(
bool Result {
bool)(
void GiveUpCompletedEventHandler(
class GiveUpCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
internal GiveUpCompletedEventArgs(
void GetQuestionTaskListCompletedEventHandler(
class GetQuestionTaskListCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
internal GetQuestionTaskListCompletedEventArgs(
0]));
}
}
}
}
更为详细的可以参见:http://www.voidcn.com/article/p-drlofvnv-dn.html
方法三:利用http 协议的get 和post
这是最为灵活的方法。

using System.Xml;
namespace Bingosoft.RIA.Common
{
利用WebRequest/WebResponse进行WebService调用的类
</summary>
class WebServiceCaller
{
#region Tip:使用说明
webServices 应该支持Get和Post调用,在web.config应该增加以下代码
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
调用示例:
Hashtable ht = new Hashtable(); Hashtable 为webservice所需要的参数集
ht.Add("str","test");
ht.Add("b","true");
XmlDocument xx = WebSvcCaller.QuerySoapWebService("http://localhost:81/service.asmx","HelloWorld",ht);
MessageBox.Show(xx.OuterXml);
#endregion
<summary>
需要WebService支持Post调用
</summary>
static XmlDocument QueryPostWebService(String URL,String MethodName,Hashtable Pars)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL +
/" +
MethodName);
request.Method =
POST";
request.ContentType =
application/x-www-form-urlencoded";
SetWebRequest(request);
byte[] data =
EncodePars(Pars);
WriteRequestData(request,data);
return readxmlResponse(request.GetResponse());
}
需要WebService支持Get调用
static XmlDocument QueryGetWebService(String URL,0); line-height:1.5!important">" + MethodName +
?" +
ParsToString(Pars));
request.Method =
GET 通用WebService调用(Soap),参数Pars为String类型的参数名、参数值
static XmlDocument QuerySoapWebService(String URL,Hashtable Pars)
{
if (_xmlNamespaces.ContainsKey(URL))
{
return QuerySoapWebService(URL,MethodName,Pars,_xmlNamespaces[URL].ToString());
}
else
{
static XmlDocument QuerySoapWebService(String URL,Hashtable Pars,255); line-height:1.5!important">string
XmlNs)
{
_xmlNamespaces[URL] = XmlNs;
加入缓存,提高效率
HttpWebRequest request =
(HttpWebRequest)HttpWebRequest.Create(URL);
request.Method =
text/xml; charset=utf-8";
request.Headers.Add(SOAPAction\"" + XmlNs + (XmlNs.EndsWith(
") ?
"" :
") + MethodName +
");
SetWebRequest(request);
byte[] data =
EncodeParsToSoap(Pars,XmlNs,MethodName);
WriteRequestData(request,data);
XmlDocument doc =
new XmlDocument(),doc2 =
new XmlDocument();
doc =
readxmlResponse(request.GetResponse());
XmlNamespaceManager mgr =
new XmlNamespaceManager(doc.NaMetable);
mgr.AddNamespace(soaphttp://schemas.xmlsoap.org/soap/envelope/");
String RetXml = doc.SelectSingleNode(
//soap:Body/*/*",mgr).InnerXml;
doc2.LoadXml(<root>" + RetXml +
</root>");
AddDelaration(doc2);
return doc2;
}
string GetNamespace(String URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL +
?WSDL");
SetWebRequest(request);
WebResponse response =
request.GetResponse();
StreamReader sr =
new StreamReader(response.GetResponseStream(),Encoding.UTF8);
XmlDocument doc =
new XmlDocument();
doc.LoadXml(sr.ReadToEnd());
sr.Close();
return doc.SelectSingleNode(
//@targetNamespace").Value;
}
byte[] EncodeParsToSoap(Hashtable Pars,String XmlNs,String MethodName)
{
XmlDocument doc =
new XmlDocument();
doc.LoadXml(<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"></soap:Envelope>");
AddDelaration(doc);
XmlElement soapBody = doc.createElement_x_x("soap","Body","http://schemas.xmlsoap.org/soap/envelope/");
XmlElement soapBody = doc.CreateElement(
BodyXmlElement soapMethod = doc.createElement_x_x(MethodName);
XmlElement soapMethod =
doc.CreateElement(MethodName);
soapMethod.SetAttribute(xmlnsstring k
in Pars.Keys)
{
XmlElement soapPar = doc.createElement_x_x(k);
XmlElement soapPar =
doc.CreateElement(k);
soapPar.InnerXml =
ObjectToSoapXml(Pars[k]);
soapMethod.AppendChild(soapPar);
}
soapBody.AppendChild(soapMethod);
doc.DocumentElement.AppendChild(soapBody);
return Encoding.UTF8.GetBytes(doc.OuterXml);
}
string ObjectToSoapXml(
object o)
{
XmlSerializer mySerializer =
new XmlSerializer(o.GetType());
MemoryStream ms =
new MemoryStream();
mySerializer.Serialize(ms,o);
XmlDocument doc =
new XmlDocument();
doc.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
if (doc.DocumentElement !=
null)
{
return doc.DocumentElement.InnerXml;
}
return o.ToString();
}
}
设置凭证与超时时间
</summary>
<param name="request"></param>
void SetWebRequest(HttpWebRequest request)
{
request.Credentials =
CredentialCache.DefaultCredentials;
request.Timeout =
10000;
}
void WriteRequestData(HttpWebRequest request,255); line-height:1.5!important">byte
[] data)
{
request.ContentLength =
data.Length;
Stream writer =
request.GetRequestStream();
writer.Write(data,0,data.Length);
writer.Close();
}
byte[] EncodePars(Hashtable Pars)
{
return Encoding.UTF8.GetBytes(ParsToString(Pars));
}
static String ParsToString(Hashtable Pars)
{
StringBuilder sb =
new StringBuilder();
if (sb.Length >
0)
{
sb.Append(&");
}
sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(Pars[k].ToString()));
}
return sb.ToString();
}
static XmlDocument readxmlResponse(WebResponse response)
{
StreamReader sr =
sr.ReadToEnd();
sr.Close();
XmlDocument doc =
new XmlDocument();
doc.LoadXml(retXml);
return doc;
}
void AddDelaration(XmlDocument doc)
{
XmlDeclaration decl = doc.CreateXmlDecl
aration(
1.0utf-8null);
doc.InsertBefore(decl,doc.DocumentElement);
}
static Hashtable _xmlNamespaces =
new Hashtable();
缓存xmlNamespace,避免重复调用GetNamespace
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。