soap调用webservice

X_Juan 2012-05-09 02:44:43
测试地址:http://api-sandbox.tg.qq.com/API/services/AccountService?wsdl
Request:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://api.tg.soso.com/advertise/accountservice/v1">
<soapenv:Header>
<token>d573b032-507f-4f07-88da-7a4019d36252</token>
</soapenv:Header>
<soapenv:Body>
<v1:getAdvertiserInfoRequest/>
</soapenv:Body>
</soapenv:Envelope>

通过WSDL.EXE生成了代理类。如何设置TOKEN来调用http://api-sandbox.tg.qq.com/API/services/AccountService?wsdl中的方法,获得数据?十万火急。希望可以给我一个可以运行的Demo。
...全文
680 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
evencom 2014-02-24
  • 打赏
  • 举报
回复
我也遇到了相似的问题,请给我一份代码吧?谢谢!谢谢! evencom@yeah.net
mimengdelei 2013-08-14
  • 打赏
  • 举报
回复
也给一份吧421805986@qq.com
yh2112003 2013-05-31
  • 打赏
  • 举报
回复
也给我一份把
a13690921367 2013-05-13
  • 打赏
  • 举报
回复
给我一份,不胜感激。931823744@qq.com
mignhe 2013-01-25
  • 打赏
  • 举报
回复
我现在也遇到了同样的问题,可否把程序也发给我一份,谢谢啦先
X_Juan 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
生成代理类后,假设代理类为Reference.cs,打开文件,手工添加和修改以下代码:


C# code

com.qq.tg.api_sandbox.AccountService client = new WindowsFormsApplication1.com.qq.tg.api_sandbox.AccountService();
client.token = new WindowsFormsApplication1.com.qq.tg.api_sandbox.MyHeader();
client.token.token = "d573b032-507f-4f07-88da-7a4019d36252";
var t = client.getAdvertiserInfo();
[/Quote]

大侠,为什么,我调用不到MyHeader啊?
AccountService client = new AccountService();
client.token.token = "d573b032-507f-4f07-88da-7a4019d36252";
var t = client.getAdvertiserInfo();
X_Juan 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

你给个邮箱,我把程序打包后给你发过去
[/Quote]
550461173@qq.com
不胜感激。
  • 打赏
  • 举报
回复
你给个邮箱,我把程序打包后给你发过去
X_Juan 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

生成代理类后,假设代理类为Reference.cs,打开文件,手工添加和修改以下代码:

C# code

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.……
[/Quote]

这位兄台,这可以加下我QQ吗?550461173
  • 打赏
  • 举报
回复
生成代理类后,假设代理类为Reference.cs,打开文件,手工添加和修改以下代码:


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/", IsNullable=false)]
public partial class MyHeader : System.Web.Services.Protocols.SoapHeader {

private string tokenField;

private System.Xml.XmlAttribute[] anyAttrField;

/// <remarks/>
public string token {
get {
return this.tokenField;
}
set {
this.tokenField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
get {
return this.anyAttrField;
}
set {
this.anyAttrField = value;
}
}
}


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.4927")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="AccountServiceSoapBinding", Namespace="http://api.tg.soso.com/advertise/accountservice/v1")]
public partial class AccountService : System.Web.Services.Protocols.SoapHttpClientProtocol {
private MyHeader _token;

public MyHeader token
{
get
{
return _token;
}
set
{
_token = value;
}

}




然后在每个你要调用的webmethod前添加这个特性:
[System.Web.Services.Protocols.SoapHeaderAttribute("token")]

比如getAdvertiserInfo()这个方法,修改后就变成:

[System.Web.Services.Protocols.SoapHeaderAttribute("token")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://api.tg.soso.com/advertise/AccountService/V1/getAdvertiserInfo", RequestElementName="getAdvertiserInfoRequest", RequestNamespace="http://api.tg.soso.com/advertise/accountservice/v1", ResponseNamespace="http://api.tg.soso.com/advertise/accountservice/v1", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("advertiser", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public AdvertiserType getAdvertiserInfo() {
object[] results = this.Invoke("getAdvertiserInfo", new object[0]);
return ((AdvertiserType)(results[0]));
}



调用:

com.qq.tg.api_sandbox.AccountService client = new WindowsFormsApplication1.com.qq.tg.api_sandbox.AccountService();
client.token = new WindowsFormsApplication1.com.qq.tg.api_sandbox.MyHeader();
client.token.token = "d573b032-507f-4f07-88da-7a4019d36252";
var t = client.getAdvertiserInfo();



在vs2008上调试通过,以上返回值,t.advertiserName = "王玉(前台测试勿动)";

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧