Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it expected behavior to use ServiceContractAttribute namespace as SOAP Response body namespace? #1054

Closed
kongxy10 opened this issue Apr 7, 2024 · 2 comments
Labels

Comments

@kongxy10
Copy link

kongxy10 commented Apr 7, 2024

To whom it may concern,
I noticed that ServiceBodyWriter.cs used ServiceContractAttribute.Namespace as the SOAP response body element namespace.

writer.WriteStartElement(_resultName, _serviceNamespace);

I was wondering if this is an expected behavior.
Should we use the MessageContractAttribute.WrapperNamespace instead?

Expected response serialization result:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <s:Body>
    <q1:WMLS_GetVersionResponse id="id1" xmlns:q1="http://www.witsml.org/message/120">
      <Result xsi:type="xsd:string">1.3.1.1,1.4.1.1</Result>
    </q1:WMLS_GetVersionResponse>
  </s:Body>
</s:Envelope>

Actual response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <s:Body>
    <q1:WMLS_GetVersionResponse id="id1" xmlns:q1="http://www.witsml.org/wsdl/120">
      <Result xsi:type="xsd:string">1.3.1.1,1.4.1.1</Result>
    </q1:WMLS_GetVersionResponse>
  </s:Body>
</s:Envelope>

Expected response body element namespace: "http://www.witsml.org/message/120"
Actual response body element namespace: "http://www.witsml.org/wsdl/120"

How to reproduce:
Original WSDL file

<?xml version='1.0' encoding='UTF-8' ?> 

<definitions name='WMLS'  targetNamespace='http://www.witsml.org/wsdl/120'
     xmlns:wsdlns='http://www.witsml.org/wsdl/120' 
     xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
     xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
     xmlns='http://schemas.xmlsoap.org/wsdl/'> 
  
<documentation>WITSML Version 1.2.0 STORE interface WSDL file
</documentation>

  
<message name='Store.WMLS_GetVersion'>
</message>
    
<message name='Store.WMLS_GetVersionResponse'>
     <part name='Result' type='xsd:string'/>
</message>
 
   
<portType name='StoreSoapPort'>

     <operation name='WMLS_GetVersion' >
          <input message='wsdlns:Store.WMLS_GetVersion' />
          <output message='wsdlns:Store.WMLS_GetVersionResponse' />
     </operation>
  
</portType>

 
<binding name='StoreSoapBinding' type='wsdlns:StoreSoapPort' >
  
     <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
    
     <operation name='WMLS_GetVersion' >
          <soap:operation soapAction='http://www.witsml.org/action/120/Store.WMLS_GetVersion' />
         <input>
             <soap:body use='encoded' namespace='http://www.witsml.org/message/120'
	      encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
         </input>
         <output>
             <soap:body use='encoded' namespace='http://www.witsml.org/message/120'
	      encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
         </output>
      </operation>  
 
  </binding>
  
<service name='WMLS' >

     <port name='StoreSoapPort' binding='wsdlns:StoreSoapBinding' >
          <soap:address location='http://We_Will_Override_this_in_our_script' />
      </port>

</service>

</definitions>

Interface generated with dotnet-svcutil tool

namespace ServiceReference1
{
    
    //ServiceContract namespace is "http://www.witsml.org/wsdl/120"   
    [System.ServiceModel.ServiceContractAttribute(Namespace="http://www.witsml.org/wsdl/120", ConfigurationName="ServiceReference1.StoreSoapPort")]
    public interface StoreSoapPort
    {
        
        [System.ServiceModel.OperationContractAttribute(Action="http://www.witsml.org/action/120/Store.WMLS_GetVersion", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true, Use=System.ServiceModel.OperationFormatUse.Encoded)]
        System.Threading.Tasks.Task<ServiceReference1.WMLS_GetVersionResponse> WMLS_GetVersionAsync(ServiceReference1.WMLS_GetVersionRequest request);
    }
    
  
   
    [System.ServiceModel.MessageContractAttribute(WrapperName="WMLS_GetVersion", WrapperNamespace="http://www.witsml.org/message/120", IsWrapped=true)]
    public partial class WMLS_GetVersionRequest
    {
        
        public WMLS_GetVersionRequest()
        {
        }
    }
    
    //Should we use the MessageContractAttribute.WrapperNamespace "http://www.witsml.org/message/120" instead?
 
    [System.ServiceModel.MessageContractAttribute(WrapperName="WMLS_GetVersionResponse", WrapperNamespace="http://www.witsml.org/message/120", IsWrapped=true)]
    public partial class WMLS_GetVersionResponse
    {
        
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
        public string Result;
        
        public WMLS_GetVersionResponse()
        {
        }
        
        public WMLS_GetVersionResponse(string Result)
        {
            this.Result = Result;
        }
    }
    
}

Use in startup.cs:

    app.UseEndpoints(endpoints =>
    {        
        endpoints.UseSoapEndpoint<StoreSoapPort>(options =>
        {
            options.Path = "/";
            options.SoapSerializer = SoapSerializer.XmlSerializer;
            options.Binding = new BasicHttpBinding
            {
                Security = new BasicHttpSecurity
                {
                    Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                    Transport = new HttpTransportSecurity
                    {
                        ClientCredentialType = HttpClientCredentialType.Basic
                    }
                },
                MaxReceivedMessageSize = int.MaxValue,
                ReaderQuotas = XmlDictionaryReaderQuotas.Max
            };
            options.WsdlFileOptions = ConfigWsdlFilePath();
            options.BufferThreshold = 20971520;
        });
    });
Copy link

github-actions bot commented May 8, 2024

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

@github-actions github-actions bot added the stale label May 8, 2024
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant