Add Header to the Simple Web Service Request

前端 未结 2 831
天命终不由人
天命终不由人 2021-01-14 08:11

I have a Console application, I add a Web reference simply by write click and use \"Add Service Reference\", then my .Config file changed to:



        
相关标签:
2条回答
  • 2021-01-14 08:57

    If i understand correctly, you want to set username and password on the header of the requests. You can achieve by using WCF Extensibility – Message Inspectors with IClientMessageInspector.BeforeSendRequest.

    Create a class that implements IClientMessageInspector. In the BeforeSendRequest method, add your custom header to the outgoing message.

    Please see this , this and this

    0 讨论(0)
  • 2021-01-14 09:03

    For add static header simply can add in .config file endpoint part so change endpoint to:

    <client>
        <endpoint address="http://ServiceAdd/FService" binding="basicHttpBinding"
         bindingConfiguration="FServiceSoapBinding" contract="MyReference.MService_"
         name="FServicePort" >
            <headers>
                <Account>
                    <username>user</username>
                    <password>password</password>
                </Account>
            </headers>
        </endpoint>
    </client>
    
    0 讨论(0)
提交回复
热议问题