1

我有一个无法解决的拦截器。问题在于由 SoapFormatter 类构建的自动生成的 SOAP 请求。我正在尝试与 WCF 服务通信并传递一些数据。我已经实现了我试图序列化为肥皂请求的类。

[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:”?

4

0 回答 0