将C#.NET Web服务的参数XML命名空间更改为空字符串

时间:2019-03-14 15:28:12

标签: c# web-services soap xml-namespaces

我用C#.NET编写了一个Web服务,作为对现有Web应用程序(.NET 3.5)的增强,为第三方软件提供了接口。

这是我的Web服务的描述:

POST /someurl/somefile.asmx HTTP/1.1
Host: someserver
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/updateServiceOrder"

<?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:Body>
    <updateServiceOrder xmlns="http://tempuri.org/">
      <VTID>int</VTID>
      <ExtID>string</ExtID>
      <FunctionCode>int</FunctionCode>
      <Status>int</Status>
      <FMExtID>string</FMExtID>
      <Termin_von>dateTime</Termin_von>
      <Termin_bis>dateTime</Termin_bis>
      <Plandauer>int</Plandauer>
      <Besuchsdauer>int</Besuchsdauer>
      <Planankunft>dateTime</Planankunft>
      <Infotext>string</Infotext>
    </updateServiceOrder>
  </soap:Body>
</soap:Envelope>

这是第三方软件尝试使用Web服务的方式:

<soap:Envelope soap:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/ xmlns:soapenc=http://schemas.xmlsoap.org/soap/encoding/ 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:Body>
      <updateServiceOrder xmlns="http://tempuri.org/">
         <VTID xmlns="">277</VTID>
         <ExtID xmlns="">1AB322823</ExtID>
         <FunctionCode xmlns="">3</FunctionCode>
         <Status xmlns="">2</Status>
         <FMExtID xmlns="">vinzenz.krenn</FMExtID>
         <Termin_von xmlns="">2019-03-14T00:00:00+01:00</Termin_von>
         <Termin_bis xmlns="">2019-03-14T00:00:00+01:00</Termin_bis>
         <Plandauer xmlns="">15</Plandauer>
         <Besuchsdauer xmlns="">15</Besuchsdauer>
         <Planankunft xmlns="">2019-03-14T09:05:00+01:00</Planankunft>
         <Infotext xmlns=""/>
      </updateServiceOrder>
   </soap:Body>
</soap:Envelope>

问题在于,当第三方软件调用我的Web服务函数时,我没有传递任何值,即所有参数似乎都为空。

我注意到他们为每个参数添加了 xmlns =“” ,我想这就是为什么我无法正确接收值的原因,但是不幸的是我不知道该怎么做进行更改以能够正确处理该呼叫(可悲的是-不能更改第三方软件的呼叫)。

我的代码很简单,看起来像这样:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Web;
using System.Web.Services;

namespace somenamespace {

  [WebService(Description="Some WebService.")]
  public class SomeImport : System.Web.Services.WebService {

    /// <summary>
    /// Create a Object
    /// </summary>
    public SomeImport() {
      //CODEGEN: This call is required by the ASP.NET Web Services Designer
      InitializeComponent();
    }

  #region Component Designer generated code

    //Required by the Web Services Designer 
    private IContainer components = null;

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent() {
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing ) {
      if(disposing && components != null) {
        components.Dispose();
      }
      base.Dispose(disposing);  
    }

  #endregion


    /// <summary>
    /// Schreibt Informationen aus Tool in den Serviceauftrag zurück.
    /// </summary>
    /// <param name="VTID">Interne ID</param>
    /// <param name="ExtID">Serviceauftragsnummer</param>
    /// <param name="FunctionCode">3: geändert, 2: gelöscht</param>
    /// <param name="Status">Obsolet</param>
    /// <param name="FMExtID">Techniker</param>
    /// <param name="Termin_von">Obsolet</param>
    /// <param name="Termin_bis">Obsolet</param>
    /// <param name="Plandauer">Einsatzdauer</param>
    /// <param name="Besuchsdauer">Obsolet</param>
    /// <param name="Planankunft">Einsatzdatum</param>
    /// <param name="Infotext">Infotext</param>
    /// <param name="Result">Result</param>
    [WebMethod]
    public void updateServiceOrder(int VTID,
                                   ref string ExtID,
                                   int FunctionCode,
                                   int Status,
                                   string FMExtID,
                                   DateTime Termin_von,
                                   DateTime Termin_bis,
                                   int Plandauer,
                                   int Besuchsdauer,
                                   DateTime Planankunft,
                                   ref string Infotext,
                                   out int Result)
    {
      try {
        Infotext = updateFromTool(VTID, ExtID, FunctionCode, FMExtID, Plandauer, Planankunft.ToString("dd.MM.yyyy hh:mm:ss"));
        Result = 0;
      } catch (Exception ex) {
        Result = 2;
        Infotext = ex.Message;
      } // try-catch
    } // updateServiceOrder
  }
}

有人可以告诉我要进行这项工作需要更改什么吗?还是我完全错过了另一个问题?

预先感谢

克莱门斯

0 个答案:

没有答案