C# soap请求中不需要的前缀

C# soap请求中不需要的前缀,c#,xml,web-services,soap,asmx,C#,Xml,Web Services,Soap,Asmx,我用C#创建了一个Web服务,我得到了一个与我期望的稍有不同的响应。似乎名称空间的一部分在我的soap节点中被用作“前缀” 这是我的WSDL的一部分: <s:complexType name="IncidentCreatedStc"> <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="CreationDate" type="s:dateTime" /> </

我用C#创建了一个Web服务,我得到了一个与我期望的稍有不同的响应。似乎名称空间的一部分在我的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>
POST localhost/PowerOn2SCADAWebservice.asmx HTTP/1.1
主机:本地主机
内容类型:text/xml;字符集=utf-8
内容长度:长度
SOAPAction:“ENMAC/TCS/IncidentCreated”
一串
但如果我发送此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>

2012-01-01
然后它就可以正常工作了,问题是我正在与之交互的程序没有用这样的XML发送soap消息,所以我需要找到一种方法从请求中删除这个“前缀”tcs

代码是:

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)
        {
            ...
        }
命名空间Web应用程序
{
/// 
///WebService的摘要描述
/// 
[WebService(Namespace=“ENMAC/TCS”)]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
//[System.Web.Script.Services.ScriptService]
公共类PowerOnGatewayService:System.Web.Services.WebService
...
[网络方法]
公共字符串IncidentCreated(字符串CreationDate)
{
...
}
大部分代码是由VisualStudio自动生成的,我不知道这些部分是否有用


知道我哪里做错了吗?

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

[DataContract(Namespace ="")]

    public class UPDATED_ACCOUNT_DETAILS_REQUEST : BASENEW
    {
        [DataMember(Order =3)]
        public string MSISDN { get; set; }
        [DataMember(Order = 4)]
        public string IMSI { get; set; }
        [DataMember(Order = 5)]
        public string ICC_ID { get; set; }
    }

您甚至可以在[datacontract(namespace=“ctc”)中给出前缀标记

您显示了WSDL的一部分,但没有显示服务中的任何代码!至少显示返回的数据类型。顺便说一句,您的问题不是前缀。问题是,
IncidentCreated
元素位于错误的命名空间中。似乎您希望它位于
http://www.tvd.co.nz
名称空间,但它是s位于
ENMAC/TCS/
名称空间中。前缀只是名称空间的别名。感谢John,我更新了帖子,网址是我的第一个名称空间,但消息返回了500,我猜是因为预期操作是ENMAC/TCS,现在返回200,但不读取XML中的任何值。这是您“做错”的原因之一您使用的是ASMX。ASMX是一项遗留技术,不应用于新的开发。WCF或ASP.NET Web API应用于所有Web服务客户端和服务器的新开发。提示:Microsoft已停用MSDN上的。您说您正在与之交互的程序“不会用这样的XML发送soap消息”。请显示它正在发送的XML。这意味着我正在接收的XML没有“前缀”,因此我需要以某种方式删除它。