将肥皂头添加到c#中的Web服务引用中#
问题描述:
我已通过在Visual Studio 2012 C#中添加服务引用添加了WSDL文件,并且已添加了一个代理类,可以使用该服务。 的问题是,我需要一个SOAP头内通过一些额外的价值,根据软件的信息,如:将肥皂头添加到c#中的Web服务引用中#
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();
}
}
我的问题是,没有任何显示,每当我点击表单按钮没有任何反应,可以请你给我一个想法,我缺少的是什么?
感谢
答
你打电话GetAllProjectMetaData后()Web服务方法,则需要设置APIKeyHeaderValue。你应该颠倒顺序:
proxy.APIKeyHeaderValue = new uondev.APIKeyHeader();
proxy.APIKeyHeaderValue.Value = "ba97e6a9-3b6d-40ac";
test.ProjectMetaData[] nc = test.GetAllProjectMetaData();
如果您仍然有问题,你可以使用Fiddler(http://www.telerik.com/fiddler),看看有什么消息已被传过线。
它工作!!!!!!非常感谢!!!!我非常感谢你的帮助! – user3790916 2014-11-03 22:29:36
@ user3790916如果这已回答您的问题,请将其标记为答案。 – Kurubaran 2014-11-04 06:27:20