SoapFormatter-如何包含名称空间?

时间:2018-09-03 11:21:13

标签: c# serialization soap soap-serialization soapformatter

我有一个无法解决的阻滞剂。问题是由SoapFormatter类生成的自动生成的SOAP请求。我正在尝试与WCF服务进行通信并传递一些数据。我实现了要尝试序列化为soap请求的类。

[Serializable]
public class MySoapClass: ISerializable
{        
    public string Username{ get; set; }
    public string Password{ get; set; }
    public int Data3 { get; set; }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.FullTypeName = "ThisIsNameIWantInSoap";
        info.AddValue("Username", Username);
        info.AddValue("Password", Password);
        info.AddValue("Data3", Data3);
    }
}

我在SoapFormatter中使用MemoryStream和MySoapClass对象。我以这种方式得到肥皂串Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Position)

生成的肥皂串不起作用,请求已交付,但是我收到“身份验证错误”,就像WCF服务无法从请求中提取任何数据一样。 这是自动生成的肥皂串:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <a1:ThisIsNameIWantInSoap id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/assem/http://tempuri.org/">
      <Username id="ref-1">username</Username>
      <Password id="ref-2">password</Password>
      <Data3>10</Data3>
    </a1:ThisIsNameIWantInSoap>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

将肥皂串复制到SoapUI并向每个参数添加名称空间标记后,一切正常。我从WCF服务获得了正确的答复。

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <a1:ThisIsNameIWantInSoap id="ref-1" xmlns:a1="http://tempuri.org/">
      <a1:Username id="ref-1">username</a1:Username>
      <a1:Password id="ref-2">password</a1:Password>
      <a1:Data3>10</a1:Data3>
    </a1:ThisIsNameIWantInSoap>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我的问题是:

-如何自动生成在每个参数中包含“ a1:”名称空间标记的肥皂字符串?

-(已回答)如何将“ a1:”命名空间更改为“ somethingElse:”?

0 个答案:

没有答案