locked
WCF SOAP Service with .net 4.5 RRS feed

  • Question

  • User-1419011324 posted

    I have created very simple soap service and it is working good but I want to add some attributes to the soap envelop My Code

    Interface

    namespace SOAPService
    {
    [ServiceContract]
    public interface IService
    {
    [OperationContract]
    double AddNumbers(double number1, double number2);
    }
    }
    
    

    svc code

    namespace SOAPService
    {
    
    public class Service : IService
    {
    public double AddNumbers(double number1, double number2)
    {
    double result = number1 + number2;
    return result;
    }
    }
    }
    
    

    When open request in SOAPUI It looks like

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
    <soapenv:Header/>
    <soapenv:Body>
    <tem:AddNumbers>
    <!--Optional:-->
    <tem:number1>1</tem:number1>
    <!--Optional:-->
    <tem:number2>1</tem:number2>
    </tem:AddNumbers>
    </soapenv:Body>
    </soapenv:Envelope>



    But I was looking output like this

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLScheme>
    <soapenv:Header/>
    <soapenv:Body>
    <tem:AddNumbers>
    <!--Optional:-->
    <tem:number1>1</tem:number1>
    <!--Optional:-->
    <tem:number2>1</tem:number2>
    </tem:AddNumbers>
    </soapenv:Body>
    </soapenv:Envelope>



    How can I add those xmlns:xsi and xmlns:xsd attributes

    Friday, May 12, 2017 11:36 AM

All replies

  • User475983607 posted

    How can I add those xmlns:xsi and xmlns:xsd attributes

    There are automatically added by the ASP framework when you use a web reference.

    Are you receiving an error?

    Friday, May 12, 2017 2:04 PM
  • User-1419011324 posted

    I have to create SOAP not consume 

    Friday, May 12, 2017 2:28 PM
  • User475983607 posted

    I have to create SOAP not consume 

    The SOAP shown is generated by the client... consuming the service...

    Are you receiving an error?  Do you need help creating the client proxy in .NET?

    https://msdn.microsoft.com/en-us/library/bb628652.aspx

    Friday, May 12, 2017 3:24 PM
  • User-1419011324 posted

    I have to create SOAP service

    I don't want to consume 

    Friday, May 12, 2017 3:26 PM
  • User475983607 posted

    I have to create SOAP service

    I don't want to consume 

    I have no idea what you're asking.  What is stopping you from creating the service?

    Friday, May 12, 2017 4:31 PM
  • User-1419011324 posted

    I want to know how to customize the SOAP message

    Friday, May 12, 2017 5:50 PM
  • User475983607 posted

    I want to know how to customize the SOAP message

    When a complex type is returned WCF will return the namespaces mentioned in your first post.  

    The data contract defines the SOAP message.  If you really have a need to output custom XML see the following link.

    https://weblog.west-wind.com/posts/2016/Apr/02/Custom-Message-Formatting-in-WCF-to-add-all-Namespaces-to-the-SOAP-Envelope

    You can also use attributes to shape the response.

    Friday, May 12, 2017 7:15 PM
  • User1877578117 posted

    I think you can do that by right-clicking on the Web.config file and choosing 'Edit WCF Configuration'.

    Maybe look under Services.Endpoints and change BindingNamespace.

    Otherwise you could probably just add something like this to your code.

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, Namespace = "http://services.whatever.com/")]
    public class Cases : ICases
    {
    }
    
    [ServiceContract(Namespace = "http://services.whatever.com/")]
    public interface ICases
    {
    
    	[OperationContract()]
    	Int32 Insert(string CaseXML);
    
    	[OperationContract()]
    	Int32 Update(string CaseXML);
    
    }

    Hope this helps.

    Saturday, June 3, 2017 6:55 PM