1

I have a blocker which I cannot solve. Issue is in auto-generated SOAP request built by SoapFormatter class. I'm trying to communicate with WCF service and pass some data. I've implemented class which I am trying to serialize to soap request.

[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);
    }
}

I'm using MemoryStream and MySoapClass object in SoapFormatter. I am getting soap string this way Encoding.UTF8.GetString(stream.GetBuffer(), 0, (int)stream.Position)

Generated soap string does not work, request is delivered, but I am getting "authentication error", just like WCF service could not extract any data from request. This is auto-generated soap string:

<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>

After copying soap string to SoapUI and adding namespace tag to every parameter, everything works fine. I am getting proper response from WCF service.

<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>

My questions are:

-How to auto-generate soap string which includes "a1:" namespace tag in every parameter?

-(Answered) How to change "a1:" namespace to"somethingElse:"?

Kalik
  • 175
  • 1
  • 11
  • The namespaces comes from the schema. Does the schema require the namespaces in all the elements? – jdweng Sep 03 '18 at 11:25
  • All existing and working requests, generated by SoapUI, have namespaces in all elements. – Kalik Sep 03 '18 at 11:32
  • Re `How to change "a1:" namespace to"somethingElse:"?` - `a1` isn't the namespace ... it is the *alias*, as defined by `xmlns:a1="http://schemas.microsoft.com/clr/assem/http://tempuri.org/"`. As long as you change the alias declaration and usage correctly, the alia scan be anything - it doesn't matter. If you want the inner objects to be in that namespace, you'll need to tell your serializer about it. Presumably `SoapFormatter` has attributes you can use to decorate your type... with `XmlSerializer` it would be `Namespace=...` on any of the `[Xml*...]` attributes – Marc Gravell Sep 03 '18 at 11:57
  • Thanks for alias info. About SoapFormatter attributes, I also thought that this is solution, but I couldn't find any attributes which could help me achieve desired formatting. – Kalik Sep 03 '18 at 12:30

0 Answers0