简体   繁体   中英

Not able To pass username and password in header of soapui in wcf service

I have one WCF service which i am trying to consume through test client project in c#,

I am using SOAPUI application then from this application i am able to pass body along with authentication in request and able decode it.

but I am able to pass soap body part through test client project but not able to pass authentication on the header along with body part in request.

this below code i have written in test client project:

AService.AServiceClient client = new AService.AServiceClient();
        AService.GetAByKeyRequest request = new AService.GetAByKeyRequest
        {
           Authorization = "xyz:123",
           AKey = "123"
        };
        var SoapResponse = ((AService.IAService)client).GetAByKey(request);

and below is some part of code in which the request is being consumed:

GetAResponse GetAByKey(GetAByKeyRequest getAByKeyRequest)
{
    //...
    string basicAuthorization = request.Headers[System.Net.HttpRequestHeader.Authorization];
    //...
}

Please give some idea

Not clear about SoapUI test client, but if you are using wcf client.You could add http header through HttpRequestMessageProperty.

 MetadataTestClient client = new MetadataTestClient();
        try
        {
            using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
            {
                HttpRequestMessageProperty property;
                if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name)){
                    property = OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
                }
                else
                {
                    property = new HttpRequestMessageProperty();
//HttpRequestMessagProperty is an item in OutgoingMessageProperties
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = property;
                }

// add property to HttpRequestMessagePropery could set HttpHeader
                property.Headers.Add (System.Net.HttpRequestHeader.Authorization, "myAuthorization");
                string re = client.HelloWorld();
            }


        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM