我有一个WCF服务,我正在尝试通过c#中的测试客户端项目使用
我正在使用SOAPUI应用程序,然后从该应用程序中我可以在请求中将主体与身份验证一起传递并能够对其进行解码。
但是我能够通过测试客户端项目传递soap正文部分,但是无法在请求中通过标头和正文部分一起通过身份验证。
我在测试客户端项目中编写的以下代码:
AService.AServiceClient client = new AService.AServiceClient();
AService.GetAByKeyRequest request = new AService.GetAByKeyRequest
{
Authorization = "xyz:123",
AKey = "123"
};
var SoapResponse = ((AService.IAService)client).GetAByKey(request);
及以下是使用请求的部分代码:
GetAResponse GetAByKey(GetAByKeyRequest getAByKeyRequest)
{
//...
string basicAuthorization = request.Headers[System.Net.HttpRequestHeader.Authorization];
//...
}
请提出一些想法
答案 0 :(得分:0)
尚不清楚SoapUI测试客户端,但如果使用的是wcf客户端。可以通过HttpRequestMessageProperty添加http标头。
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();
}
}