繁体   English   中英

将肥皂标头添加到C#中的Web服务引用

[英]adding a soap header to a web service reference in c#

我通过在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文件,所以我不需要重新构建肥皂消息,所以我只需要使用有问题的服务。 在Value病内部,是能够调用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 )查看通过网络传输的消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM