简体   繁体   English

如何解决 Soap header 动作不理解?

[英]How to resolve Soap header action not understood?

I'm developing on VS2008 for Windows Mobile 6.5 Professional I get this error message "Soap header action not understood"我正在为 Windows Mobile 6.5 Professional 在 VS2008 上开发我收到此错误消息“Soap header 操作不理解”

I see a lot of post on the subject but none for Windows Mobile.我看到很多关于这个主题的帖子,但没有关于 Windows Mobile 的帖子。

Any help would be appreciated.任何帮助,将不胜感激。

Link to the URL with the XML data使用 XML 数据链接到 URL

https://silulumanzi.4most.co.za:4343/SIZA.svc?wsdl https://silulumanzi.4most.co.za:4343/SIZA.svc?wsdl

How Rene and what silulumanzi.4most.co.za:4343/SIZA.svc suggested? Rene 和silulumanzi.4most.co.za:4343/SIZA.svc 的建议如何?

public void GetOpenPO()
    {
        //Get open purchase order numbers and populate combo box

        try
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            //binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
            EndpointAddress ea = new EndpointAddress(new Uri("https://silulumanzi.4most.co.za:4343/SIZA.svc?wsdl"));

            SizaWS.SIZA client = new SizaWS.SIZA();

            string[] Response = client.GetOpenPO();

            //Popuplate combo box with data received from web service
            comboBox2.Items.Add("");
            for (int i = 0; i < Response.Length; i++)
            {
                if ((!String.IsNullOrEmpty(Response[i])))
                {
                    comboBox2.Items.Add(Response[i]);
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error");
        }
    }

No service reference无服务参考

在此处输入图像描述

Config File I added我添加的配置文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ISIZA" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
        transactionFlow="false" hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
          enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
            establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="https://silulumanzi.4most.co.za:4343/SIZA.svc"
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISIZA"
      contract="ISIZA" name="WSHttpBinding_ISIZA" />
</client>
</system.serviceModel>
</configuration>

Error List错误列表

在此处输入图像描述

The version System.ServiceModel版本 System.ServiceModel

在此处输入图像描述

I don't have a fully working VS2008 but I've reproduced your problem and here are the steps to resolve the problem you face for one specific call, in this case GetOpenPO.我没有完全正常工作的 VS2008,但我已经重现了您的问题,这里是解决您在一个特定呼叫中遇到的问题的步骤,在这种情况下是 GetOpenPO。 It is a hack.这是一个黑客。 I can't find a better solution for now.我暂时找不到更好的解决方案。

First of all, get rid of the Web Refence and the Service Reference and any files you added based on my comments.首先,删除 Web 参考和服务参考以及您根据我的评论添加的任何文件。

Add the textfile 'GenClient.xml' to your project and enter the following options (based on documentation found here )将文本文件“GenClient.xml”添加到您的项目并输入以下选项(基于此处找到的文档)

<?xml version="1.0" encoding="utf-8" ?>
<wsdlParameters xmlns="http://microsoft.com/webReference/">
  <webReferenceOptions>
    <verbose>false</verbose>
    <codeGenerationOptions>properties oldAsync</codeGenerationOptions>
    <style>client</style>
  </webReferenceOptions>
</wsdlParameters>

After saving this achieves that the service client gets generate with.Net 1.1 style Begin/EndInvoke methods, omitting any use of System.Threading.保存后,服务客户端将使用 .Net 1.1 样式的 Begin/EndInvoke 方法生成,省略了对 System.Threading 的任何使用。

Open the Visual Studio 2008 Command prompt.打开 Visual Studio 2008 命令提示符。 Change Directory to your project directory.将目录更改为您的项目目录。 Run the following command to generate a SIZA.cs class that will act as your soap client (it takes the earlier created and saved genclient.xml as parameters file):运行以下命令生成一个 SIZA.cs class 作为您的 soap 客户端(它采用之前创建并保存的 genclient.Z0F635D0E0F3874FFF8B581C132E6C7A7 作为参数文件):

This will overwrite your current SIZA.cs.这将覆盖您当前的 SIZA.cs。 Re-apply changes afterwards之后重新应用更改

wsdl /out:SIZA.cs /protocol:soap12 /parameters:genclient.xml https://silulumanzi.4most.co.za:4343/SIZA.svc?wsdl

You will now have a SIZA.cs file in your project folder.现在,您的项目文件夹中将有一个 SIZA.cs 文件。

Open your project in Visual Studio 2008. In the solution explorer, right-click your project, Add Existing Item and in the filedialog and find the SIZA.cs in your project root folder.在 Visual Studio 2008 中打开您的项目。在解决方案资源管理器中,右键单击您的项目,添加现有项目,然后在文件对话框中找到项目根文件夹中的 SIZA.cs。

In the solution Explorer, right click on References, choose "Add Reference", wait for the dialog to load and then from the.Net tab find and select assembly System.Web.Services, click OK.在解决方案资源管理器中,右键单击引用,选择“添加引用”,等待对话框加载,然后从.Net 选项卡中找到 select 程序集 System.Web.Services,单击确定。

Your solution should compile now without errors.您的解决方案现在应该可以无错误地编译。

This is where the hack starts:/这是黑客开始的地方:/

In the SIZA.cs file find the following method:在 SIZA.cs 文件中找到以下方法:

public string[] GetOpenPO() {

Right before that method add this Attribute:在该方法之前添加此属性:

[System.Web.Services.Protocols.SoapHeader("Soap12HdrGetOpenPO", Direction = SoapHeaderDirection.InOut)]

Your end result should look like this:您的最终结果应如下所示:

/// <remarks/>    
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ISIZA/GetOpenPO", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlArrayAttribute(IsNullable=true)]
[return: System.Xml.Serialization.XmlArrayItemAttribute(Namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays")]

[System.Web.Services.Protocols.SoapHeader("Soap12HdrGetOpenPO", Direction = SoapHeaderDirection.InOut)]

public string[] GetOpenPO() {
    object[] results = this.Invoke("GetOpenPO", new object[0]);
    return ((string[])(results[0]));
}

Create a new Class file and name it: SIZA.Partial.cs创建一个新的 Class 文件并将其命名为:SIZA.Partial.cs

Add the following code in that new file, replacing everything that is in it:在该新文件中添加以下代码,替换其中的所有内容:

using System.Web.Services.Protocols;
using System.Xml;

public partial class SIZA
{

    private SoapUnknownHeader CreateSoapAcionHeader(string hdr, string value)
    {
        var xd = new XmlDocument();
        var sh = new SoapUnknownHeader();
        sh.MustUnderstand = true;
        sh.Element = xd.CreateElement(hdr, "http://www.w3.org/2005/08/addressing");
        sh.Element.InnerText = value;
        return sh;
    }

    // this method gets called due to the added SoapHeader attribute
    public SoapUnknownHeader[] Soap12HdrGetOpenPO
    {
        get
        {
            return new[]
                {
                    CreateSoapAcionHeader("Action", "http://tempuri.org/ISIZA/GetOpenPO"), 
                    CreateSoapAcionHeader("To", this.Url), 
                };
        }
        set { /* empty */}
    }
}

This will basically add the missing SOAP12 Action and To header to the soap envelope for the GetOpenPO call.这基本上会将缺少的 SOAP12 Action 和 To header 添加到 GetOpenPO 调用的 soap 信封中。 And that makes the WCF service you're calling happy as well.这使得 WCF 服务也让您感到高兴。

Here is a fiddler screenshot of what gets exchanged on the wire:这是在网络上交换的内容的提琴手屏幕截图:

在此处输入图像描述

The downside of this solution is that you need to do this manually for every public method in the SIZA client you want to use.此解决方案的缺点是您需要为要使用的 SIZA 客户端中的每个公共方法手动执行此操作。 Maybe someone else comes by and remembers how one of the extension points in the SoapHttpClientProtocol should be leveraged.也许其他人过来并记得应该如何利用SoapHttpClientProtocol中的扩展点之一。

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

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