SoapCore icon indicating copy to clipboard operation
SoapCore copied to clipboard

How to Remove extra response tag from my Soap Response

Open srigaux opened this issue 8 years ago • 12 comments

I have below code for my service :

    [XmlType(Namespace="http://djm.eu/services/sample/v1")]
    [XmlRoot("MyResponse", Namespace="http://djm.eu/services/sample/v1", IsNullable=false)]
    public class MyResponseType
    {
        public int Code { get; set; }
        public string Description { get; set; }
    }


    [ServiceContract(Namespace = @"http://djm.eu/services/sample/v1")]
    public interface IMyService
    {
        [OperationContract]
        [return:MessageParameter(Name = "MyResponse")]
        MyResponseType Foo();
    }

    public class MyService : IMyService
    {
        public MyResponseType Foo()
        {
            return new MyResponseType
            {
                Code = 200,
                Description = "Ok"
            };
        }
    }

and this is the result :

<s:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <FooResponse xmlns="http://djm.eu/services/sample/v1">
         <MyResponse>
            <Code>200</Code>
            <Description>Ok</Description>
         </MyResponse>
      </FooResponse>
   </s:Body>
</s:Envelope>

The problem is I dont want that extra <FooResponse> tag created automatically. I want it completely remove (SoapParameterStyle.Bare).

Expected result:

<s:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <MyResponse xmlns="http://djm.eu/services/sample/v1">
          <Code>200</Code>
          <Description>Ok</Description>
      </MyResponse>
   </s:Body>
</s:Envelope>

Thanks.

srigaux avatar Jul 04 '18 08:07 srigaux

Yeah, I have the same problem. I commented out couple of code rows in this engine and now it's OK, doesn't duplicate, puts some extra default namespaces but that's OK, I can live with that. Pretty nasty solution I did but don't see better at the moment, maybe in the future!

SvarigsCilveks avatar Jul 19 '18 14:07 SvarigsCilveks

fixed it here

DmitryBryluk avatar Aug 03 '18 19:08 DmitryBryluk

Please, check https://www.nuget.org/packages/SoapCore/0.9.8.3

kotovaleksandr avatar Aug 07 '18 10:08 kotovaleksandr

upd: https://www.nuget.org/packages/SoapCore/0.9.8.4

kotovaleksandr avatar Aug 07 '18 11:08 kotovaleksandr

Seems that this is fixed pretty well n can be closed! Well done @DmitryBryluk !

tomskarasha avatar Aug 13 '18 18:08 tomskarasha

why am i getting a "This XML file does not appear to have any style information associated with it. The document tree is shown below."

jhnkrl15 avatar Sep 11 '18 06:09 jhnkrl15

Has this issue been solved? @DmitryBryluk and @tomskarasha comments give that impression, but when I try the sample provided by @srigaux I still end up with a nested FooResponse and MyResponse which I was hoping to avoid. (FYI: my use case is to mock another external web service for testing purposes. But I am not able to re-create ws because I get this extra element in every soap action's request and response.)

bremnes avatar Nov 29 '18 08:11 bremnes

it is explained in serialization tests. under some conditions you may avoid extra response tag, do not remember details

DmitryBryluk avatar Nov 29 '18 09:11 DmitryBryluk

fixed it here

Can you put a example to how to do this, please? Maybe the correction of srigaux's code

rraymundes avatar Apr 30 '19 16:04 rraymundes

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 27 '21 02:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Aug 11 '21 02:08 github-actions[bot]

Has this issue been solved? @DmitryBryluk and @tomskarasha comments give that impression, but when I try the sample provided by @srigaux I still end up with a nested FooResponse and MyResponse which I was hoping to avoid. (FYI: my use case is to mock another external web service for testing purposes. But I am not able to re-create ws because I get this extra element in every soap action's request and response.)

Had a similar issue and was able to fix this usign MessageContract and MessageBodyMember. you can give it a try if you still facing this extra xml in the response.

ajeyaprakash148 avatar Sep 28 '24 12:09 ajeyaprakash148