【发布时间】:2014-11-03 22:10:41
【问题描述】:
我已经通过在 Visual Studio 2012 C# 中添加服务引用来添加 WSDL 文件,并且已经添加了一个代理类,我可以使用有问题的 Web 服务。 问题是我需要根据软件信息在soap头中传递一些额外的值,例如:
POST /uondevws/Dashboard.asmx HTTP/1.1
Host: uondev.bluera.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetAllProjectMetaData"
<?xml version="1.0" encoding="utf-8"?>
<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:Header>
<APIKeyHeader xmlns="http://tempuri.org/">
<Value>string</Value>
</APIKeyHeader>
<Message xmlns="http://tempuri.org/">
<Value>string</Value>
</Message>
</soap:Header>
<soap:Body>
<GetAllProjectMetaData xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
但是由于我已经添加了 WSDL 文件,我不需要重新构建soap 消息,我只需要使用相关服务即可。在值内部将是能够调用 API 的关键 这是我的代码:所有这些都是在一个按钮内的 Windows 窗体中完成的,所以当我单击该按钮时,我可以显示 foreach 函数内的所有字段
namespace GetAllMetaDataApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
test.Dashboard proxy = new test.Dashboard();
test.ProjectMetaData[] nc = test.GetAllProjectMetaData();
proxy.APIKeyHeaderValue = new test.APIKeyHeader();
proxy.APIKeyHeaderValue.Value = "ba97e6a9-3b6d-40ac";
StringBuilder sb = new StringBuilder();
foreach (test.ProjectMetaData som in nc)
{
sb.AppendLine("\r\n");
sb.AppendLine("\r\n" + som.ProjectTitle + " " + som.ProjectID + " " + som.PublishStatus);
}
//StringBuilder.StringBuilder();
label1.Text = sb.ToString();
}
}
我的问题是什么都没有显示,每当我点击表单按钮时什么都没有发生,你能告诉我我错过了什么吗?
谢谢
【问题讨论】:
标签: c# winforms visual-studio-2012 proxy wsdl