soap请求中不需要的前缀

时间:2014-05-08 04:03:10

标签: c# xml web-services soap asmx

我在C#中创建一个webService,我的回复与我期待的有点不同。似乎名称空间的一部分在我的soap节点中被用作“前缀”。

这是我的WSDL的一部分:

  <s:complexType name="IncidentCreatedStc">
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="CreationDate" type="s:dateTime" />
    </s:sequence>
  </s:complexType>
  <s:element name="IncidentCreatedResponse">

这是我在browner中看到的预期请求:

POST localhost/PowerOn2SCADAWebservice.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "ENMAC/TCS/IncidentCreated"

<?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>
<IncidentCreated xmlns="ENMAC/TCS">
      <CreationDate>string</CreationDate>
     </IncidentCreated>
  </soap:Body>
</soap:Envelope>

但是如果我发送这个XML,那么CreationDate字段将为空,但如果我发送:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tcs="ENMAC/TCS/">
   <soap:Header/>
   <soap:Body>
      <tcs:IncidentCreated>
         <tcs:CreationDate>2012-01-01</tcs:CreationDate>
      </tcs:IncidentCreated>
   </soap:Body>
</soap:Envelope>

然后它工作正常,问题是我与之接口的程序不会发送带有这样的XML的soap消息,所以我需要找到一种方法从请求中删除这个“前缀”tcs。 / p>

代码是:

namespace WebApplication
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "ENMAC/TCS")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]


    public class PowerOnGatewayService : System.Web.Services.WebService

...
        [WebMethod]
        public string IncidentCreated (string CreationDate)
        {
            ...
        }

大部分代码都是由Visual Studio自动生成的,我不知道这些部分是否会有所帮助

我做错了什么想法?

1 个答案:

答案 0 :(得分:0)

前缀取自WCF服务中的默认命名空间。如果要更改前缀标记,请使用类属性中的namespace元素,如下所示

df_Date = df[df['state'].str.contains('Traded Away') & df['maturity_date']!=0][['state','maturity_date']]
df_Date['maturity_date'] = pd.to_datetime(df_Date['maturity_date'])
df_Date['Today'] = pd.to_datetime('today') 
df_Date['Days'] = (df_Date['maturity_date'] - df_Date['Today'])
print(df_Date.head(10))


          state maturity_date      Today       Days
0   Traded Away    2018-03-15 2018-03-19    -4 days
10  Traded Away    2025-06-15 2018-03-19  2645 days
12  Traded Away    2047-03-21 2018-03-19 10594 days
15  Traded Away    2166-03-15 2018-03-19 54052 days
17  Traded Away    2166-12-18 2018-03-19 54330 days
20  Traded Away    2023-05-04 2018-03-19  1872 days
22  Traded Away    2027-11-15 2018-03-19  3528 days
23  Traded Away    2025-03-15 2018-03-19  2553 days
25  Traded Away    2023-01-15 2018-03-19  1763 days
26  Traded Away    2166-05-01 2018-03-19 54099 days

您甚至可以在[datacontract(命名空间=&#34; ctc&#34;)]

中提供前缀标记